This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to display value in htmlSelectOneMenu

 
Balaji Kadam
Ranch Hand
Posts: 31
Hibernate Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all.
i have bind htmlSelectOneMenu. it contains some value. I want to set or display a value after a process.
How to change value
i have tried using setValue method of both binding property and value property of htmlSelectOneMenu.

Same issue is with InputTextArea. how to set value in it via code(RowSelectionListener of icefaces)
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forget about binding. It's something that people do too often for the wrong reasons.

If you have a selectOneMenu like this:


You can set the selection in Java code by simply invoking the "set" method: "setSelection(newValue)".

Please note that SelectOneMenu has built-in validation, however, and if you attempt to set a value that's not in the selectItems list, you'll have problems.

 
Balaji Kadam
Ranch Hand
Posts: 31
Hibernate Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply

You can set the selection in Java code by simply invoking the "set" method: "setSelection(newValue)".


what to set in value
itemValue or itemLabel .
i am trying itemvalue but it doesnot set properly
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You always set the Value. The label is just for the user's display.

As I said, if the value isn't present in the selectItem list, the attempt will fail.
 
Balaji Kadam
Ranch Hand
Posts: 31
Hibernate Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
value isn't present in the selectItem list.
setValue() method invokes twice. when invokes first it contains proper value but next time it contains null so it doesn't display any value selected in it.

How to avoid second call.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Value MUST be in the selection list. That is not an option. If it is not, the value WILL be reset.

You also have no control over how many times set/get methods will be called on a property during the JSF request processing lifecycle. Which is why side-effects and long-running operations should not appear in get/set methods.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic