my dog learned polymorphism*
The moose likes JSF and the fly likes how to display value in htmlSelectOneMenu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "how to display value in htmlSelectOneMenu" Watch "how to display value in htmlSelectOneMenu" New topic
Author

how to display value in htmlSelectOneMenu

Balaji Kadam
Ranch Hand

Joined: Apr 27, 2010
Posts: 31

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

Joined: Jun 25, 2001
Posts: 16022
    
  20

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Balaji Kadam
Ranch Hand

Joined: Apr 27, 2010
Posts: 31

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

Joined: Jun 25, 2001
Posts: 16022
    
  20

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

Joined: Apr 27, 2010
Posts: 31

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

Joined: Jun 25, 2001
Posts: 16022
    
  20

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to display value in htmlSelectOneMenu