value bound to h:selectOneMenu doesn't get set

Error: value bound to h:selectOneMenu doesn't get set

Possible Solution:

This problem has given me serious problems on three different occasions. To summarize the problem, I've created an h:selectOneMenu control on a form. I've set the value attribute to be a property of a Seam component. The value is supposed to serve a bi-directional purpose. If it is non-null when the control is rendered, then the specified value will be selected in the resulting combo box. I haven't had any problems at all getting this to work. The problem is with the other direction. When the user selects a new item in the combo box, the property in the value field is supposed to get set using the class setter for the property.

So, I've had several issues, including just not understanding some things. I will try to document them all here.
  1. The name specified in the value field should be a Seam component property, NOT a Seam context variable. For example, you should probably be using value="#{myList.selectedValue}" AND NOT value="#{selectedValue}". The first way will call the setSelectedValue() method of the class corresponding to the myList Seam component. The second will get the correct value when rendered, but I don't believe it will result in setting the value when it's changed. But I might be wrong about that.
  2. The name you specify must equate to a Seam component name (i.e. something specified as @Name("name"). So, in the example above, you would need a class with @Name("myList") that defines a selectedValue property and implements a getter and setter for the selectedValue property. Note that if it's an EJB3.0 bean, then you will also need to define the getter and setter in the corresponding interface.
  3. Of course, you're probably going to want to promote the changed value to a Seam context, so you'll probably declare the selectedValue property as an outjected context variable by placing an @Out annotation above the property declaration.
  4. This to me was one of the trickier points that I did not see documented anywhere: the setter method is NOT called when the user selects one of the items in the combo box. Coming from a heavy JavaScript background, I assumed I'd see the setter get called each time I changed the combo box selection. However, instead, the setter is only called when the page goes away. Note, that if you have commandLinks on the page that rerender the page, that will also cause the setter to get called. Hence, the value should remain set after a rerender. The setter gets called whether the destination page is the same page or not. So, if you're debugging and trying to follow along, don't expect the setter to get called until a button is pressed.
  5. This one was also tricky for my JavaScript-addled brain. The valueChangedListener attribute is NOT used to specify a method that gets called when the user selects a new item. The valueChangedListener only gets called when the property value changes.
  6. Now for the most tricky point of all. THE selectOneMenu control MUST RESIDE IN THE SAME FORM AS THE BUTTON WHICH IS USED TO EXIT THE PAGE!!! I spent about eight hours trying to figure this one out. My page had two separate forms, one of them for my wizard-style buttons (because they are defined in a template.xhtml). I finally discovered the cause of the problem when I realized that one button on the page that just did a reselect of data for the combo box DID result in calling the setter, but the other button (to go to the next page) DID NOT!!. Once I put all the buttons into the same form as the combo box, it worked perfectly.

 del.icio.us  Digg 

 
Trackbacks
  • No trackbacks exist for this entry.
Comments

  • 4/22/2009 6:37 AM Poria wrote:
    Good afternoon. It is only possible to live happily ever after on a day-to-day basis.
    I am from Liechtenstein and too poorly know English, give true I wrote the following sentence: "Offers online reservations for flights from the"

    Waiting for a reply , Poria.
    Reply to this
  • 5/21/2009 1:55 AM henady wrote:
    thanks, this helps
    Reply to this
  • 6/2/2009 7:01 AM boediger wrote:
    The first way will call the setSelectedValue() method of the class corresponding to the myList Seam component. The second will get the correct value when rendered, but I don't believe it will result in setting the value when it's changed. But I might be wrong about that.

    boediger
    Reply to this
  • 7/8/2009 9:59 PM web design wrote:
    very good post.It will help a lot.
    Reply to this
  • 9/5/2009 1:28 AM London Escorts wrote:
    I tried several variations of this(DR4 & Seam1.2.1) as well and always the value of the list is null. Am trying to track down in the component rendering where we are losing (or not getting this value). Of course, the list could be created by a backing bean and then used in the selectOneMenu for now, but will let you know where we get to with reviewing this
    Has anyone else here been looking at this as well? Recently we have been concentrating on getting our ice tags working as they would normally. Thanks for drawing this valuable s tag to our attention.
    Reply to this
  • 1/28/2010 7:49 PM ppo insurance plans wrote:
    Thanks, i new i had seen an example of this somewhere, but your example is clear and to the point. Thanks
    Reply to this
Leave a comment

 Enter the above security code (required)

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.