[jboss-user] [JBoss Seam] - Re: EnumConverter
sjmenden
do-not-reply at jboss.com
Thu Apr 12 10:22:52 EDT 2007
Use seams built in enum handling:
Here is an example of handling a True/False Enum
| <h:outputLabel for="active">
| Active
| <span class="required">*</span>
| </h:outputLabel>
| <s:decorate id="activeDecoration">
| <h:selectOneMenu id="active" value="#{testHome.instance.active}">
| <s:convertEnum />
| <s:enumItem enumValue="TRUE" label="True" />
| <s:enumItem enumValue="FALSE" label="False" />
| </h:selectOneMenu>
| </s:decorate>
|
| public enum BooleanEnum {
| TRUE("TRUE"),
| FALSE("FALSE");
| private final String name;
|
| /**
| * Prevent instantiation and subclassing with a private constructor.
| */
| private BooleanEnum(String name) {
| this.name = name;
| }
|
| private static final Map INSTANCES = new HashMap();
|
| static {
| INSTANCES.put(TRUE.toString(), TRUE);
| INSTANCES.put(FALSE.toString(), FALSE);
| }
|
| // ********************** Common Methods ********************** //
|
| public String toString() {
| return name;
| }
|
| Object readResolve() {
| return getInstance(name);
| }
|
| public static JobStatus getInstance(String name) {
| return (JobStatus) INSTANCES.get(name);
| }
| }
|
And in the entity:
| @Enumerated(EnumType.STRING)
| @Column(name="ACTIVE")
| @NotNull
| public BooleanEnum getActive() {
| return active;
| }
| public void setActive(BooleanEnum active) {
| this.active = active;
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4036737#4036737
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4036737
More information about the jboss-user
mailing list