aspose file tools*
The moose likes JSF and the fly likes Selecting option in second selectOneMenu not setting property value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Selecting option in second selectOneMenu not setting property value" Watch "Selecting option in second selectOneMenu not setting property value" New topic
Author

Selecting option in second selectOneMenu not setting property value

D Plum
Greenhorn

Joined: Jan 27, 2011
Posts: 4
Hi,
I have been working on this problem for hours and cannot find an answer in this forum or any other google search.
I have a form that contains 2 dropdowns populated from database tables, when an option is selected in the first one (system) it successfully triggers the rendering and populating of the second (facility). Great. But...when the user selects from the second dropdown, the bean's property (ie selectedFac) is always null. I need the 2 values, system and facility, to then find the person in the database.

Using JSF 2, glassfish 3. No richfaces etc

Here's the JSF:


When I view the html source I see the first list has an option selected but not the second:



I know the code is OK for the second dropdown because when I remove the first one (and add some hardcoding in the bean for the "system" value) the property is set fine and I can see the option selected on the HTML source.
Has anyone come accross this before? Any ideas or suggestions would be appreciated.

D.Plum
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16242
    
  21

I did a very superficial look at this and one thing jumped out:


I don't think that's doing what you think it's doing, although it might work for the wrong reason.

EL has a tidier way:



"null" is not a manifest constant in EL.

Since I didn't actually do a close look, I don't know if this will actually fix the problem, but it fixes a problem. If you're having an issue with a dependent selectOneMenu, it's probably got to do with the fact that the only allowable options for the selected value are those that are in its selectItems list. JSF will zap anything that isn't in there.


Customer surveys are for companies who didn't pay proper attention to begin with.
D Plum
Greenhorn

Joined: Jan 27, 2011
Posts: 4
Thanks Tim, I made the change you suggested and unfortunately the behaviour has not changed (but I appreciate the code review)
I didn't quite understand your second comment though, can you elaborate?
Perhaps you could post some example code if you have it for 2 drop downs with one dependant on the other could help? I'm at a loss
D hanu
Greenhorn

Joined: Jan 30, 2011
Posts: 4

I tried this and I found a solution. Check if this works for you.




When i tried using binding attribute for the second drop down, it did work for me.
D Plum
Greenhorn

Joined: Jan 27, 2011
Posts: 4
I'm not sure how binding the component to the backing bean will help me, the problem I have is the item in the menu is not being selected ie the "selected" attribute of the option element in the second select element is not set:

This is the first select element with the selected item rendered:

But the second one has no selection:


Still can't work out why, would the backing bean code help?


D hanu
Greenhorn

Joined: Jan 30, 2011
Posts: 4

A value appears as selected in html only when page is rendered. Try loading the page and you will find that the first dropdown would also not have any selected option.

But once you select an item, since the page is re-rendered due to valuechangelistener, html code would appear as selected. Try re-rendering the page second time to see the second dropdown value selected.
D Plum
Greenhorn

Joined: Jan 27, 2011
Posts: 4
Hi reloading the page didn't change anything. The second property "#{dataAccess.selectedFac}" is definitely not being set because I use it to conditionaly render a text box for the next step ie user can enter an account number and look up the person details.

Please, does any one have an idea? Here's my backing bean code which I know has some problems like executing SQL in the getters but it works:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Selecting option in second selectOneMenu not setting property value