The getSelected method should return the "value" of the SelectItem not the 
"label". That's what is wrong in your code.

-----Original Message-----
From: Slawek [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 17, 2005 2:59 PM
To: MyFaces Discussion
Subject: Re: whats wrong with combobox


i have:)

        }
        //other getters and setters
}

i just didnt want to paste all obvious code...


> You don't have a setter in your bean. I don't know how you are getting 
> the correct value printed. Try with a setter for the member "selected" 
> in your bean.
>
> -----Original Message-----
> From: Slawek [mailto:[EMAIL PROTECTED]
> Sent: Thursday, February 17, 2005 2:14 PM
> To: [email protected]
> Subject: whats wrong with combobox
>
>
> i want to put combobox on the page and submit button. after submit and
> performing somme action view returns to the _same_ page. then i'd like to
> see in that combobx value that i just jave selected. for exampe combo 
> have
> values: 1111, 2222, 33333 and i choose 2222 -> click button ->request ->
> response. after that i'd like to see the combo set to 2222 but NOT 1111.
> in other words i'd like that HTML option 2222 has property selected.
>
> im trying to do it like this:
> //=======view=========
> <f:view>
> <h:form>
>       <h:selectOneMenu value="#{test.selected}">
>               <f:selectItems value="#{test.options}"/>                
>       </h:selectOneMenu>
>
>       <h:commandButton action="#{test.act}"/>
> </h:form>
> </f:view>
> //===========bean=======
> public class Test {
>       public Test(){
>       }
>       public String act(){
>               System.out.println(">>>>>>act"+selected);
>               return "go_back";
>       }
>       
>       private String selected;
>       private SelectItem[] options;
>
>       public SelectItem[] getOptions() {
>               options;new SelectItem[3];
>               options[0]=new SelectItem("1","1111");
>               options[1]=new SelectItem("2","2222");
>               options[2]=new SelectItem("3","3333");
>               return options;
>       }
>       public String getSelected(){
>               System.out.println(">>>>>>geter"+selected);
>               return selected;
>       }
>       //other geters and seters
> }
>
> after submit i can see correct string on the console (writen by act and
> getSelected) BUT on the gage i can see combo with text 1111. what can i 
> do
> wrong? where should i search for bug?
>
> thanks
>
> Slawek


Reply via email to