• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Selecting option in second selectOneMenu not setting property value

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
D Plum
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 4
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

reply
    Bookmark Topic Watch Topic
  • New Topic