This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

selectOneMenu to a managed bean

 
Michael Binette
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this code in the JSF:



where contract.contract.districtId points to a bean, class=District that has id, name, and region properties.

contract.contract is a bean, class=Contract that has a districtId property that is of type class=District.

contract.districtIds is a method that returns an array of SelectItem. The SelectItem is created with a value of a class=District bean and a label of the District.name property for example:



When loading the JSF it properly shows the existing value but when I submit the form, without even changing the displayed value, my contract.contract.districtId object becomes null. I'm not really sure where to start looking for the cause. What am I doing wrong?
 
Adam Mazurek
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can You show us the beans source code?
 
Michael Binette
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
District (referenced by contract.contract.districtId) is an entity bean with generic getter and setters for the id, name, and region vars. Nothing special.

Contract is an entity bean (referenced by contract.contract) with getter and setters for a ton of fields. The districtId property isn't really an Id. It is the District entity. The districtId getter and setters are:


The JSF has a commandLink that with an action of "#{contract.edit}". The edit method looks like:

where ContractService is an access layer on top of the entity beans. I debugged to this call and at the first line of this method, contract.districtId is null.
 
Adam Mazurek
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe You should add this entity bean, which is on Your managed-bean as a managed property in config? I have problem with entity bean, which was a attribute of some bean - on page it was dissapearing. The solution was to add a markup <t:saveState >, but it is available only in myfaces.
 
Michael Binette
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to JSF and I think I thought the oneSelectMenu had a little more "magic" than it really does. What I ended up trying that worked was to add a districtId property so instead of having the oneSelectMenu have a value of contract.contract.districtId which was pointing to a District object, I have the value be contract.districtId which is pointing to a Long in the backing bean.

Then when they submit the form I use the contract.districtId to find the District and set contract.contract.districtId using it.
 
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!