[jboss-user] [JBoss Seam] - Re: always got data model update error when enum happens in
ellenzhao
do-not-reply at jboss.com
Wed Nov 22 12:09:49 EST 2006
Voila! Thanks for the hint and now it is working perfectly.
My solution is based on hotchai's solution here:
http://jroller.com/page/hotchai?entry=jsf_converter_for_jdk_1
(I am using Seam 1.1 beta 2 and all the example source code are from Seam 1.1 beta 2 as well)
The EnumConverter class can be used as it is, no need to modify and it simply works.
Here is my Enum classes:
| public class User implements Serializable {
| // same as the booking sample
| public static enum Gender{
| FEMALE("female"), MALE("male");
| private String label;
|
| Gender(String label){
| this.label = label;
| }
|
| public String getLabel(){
| return this.label;
| }
| }
|
| public static enum Title {
| DR("Dr."), MS("Ms."), MR("Mr."), MRS("Mrs.");
| private String label;
|
| Title(String label) {
| this.label = label;
| }
|
| public String getLabel() {
| return this.label;
| }
| }
| }
|
| here is the code from backing bean:
|
| @Stateful
| @Scope(EVENT)
| @Name("register")
| public class RegisterBacking implements Register {
| //...
| private SelectItem[] titleItems;
| private SelectItem[] genderItems;
|
| //... same as the booking example
| public SelectItem[] getTitleItems() {
| this.titleItems = new SelectItem[Title.values().length];
| int i = 0;
| for (Title t : Title.values()) {
| this.titleItems[i++] = new SelectItem(t, t.getLabel());
| }
| return this.titleItems;
| }
|
| public SelectItem[] getGenderItems() {
| this.genderItems = new SelectItem[Gender.values().length];
| int i = 0;
| for (Gender g : Gender.values()) {
| this.genderItems[i++] = new SelectItem(g, g.getLabel());
| }
| return this.genderItems;
| }
| }
|
| The code in register.xhtml:
|
| <div class="entry">
| <div class="label"><h:outputLabel for="title">Title:</h:outputLabel></div>
| <div class="input"><s:decorate>
| <h:selectOneMenu id="title" value="#{guest.title}" required="true">
| <f:selectItems value="#{register.titleItems}" />
| </h:selectOneMenu>
| <br />
| </s:decorate></div>
| </div>
|
| <div class="entry">
| <div class="label"><h:outputLabel for="gender">Gender:</h:outputLabel></div>
| <div class="input"><s:decorate>
| <h:selectOneMenu id="gender" value="#{guest.gender}"
| required="true">
| <f:selectItems value="#{register.genderItems}" />
| </h:selectOneMenu>
| <br />
| </s:decorate></div>
| </div>
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3987942#3987942
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3987942
More information about the jboss-user
mailing list