Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with h:selectOneMenu  RSS feed

 
bash bashtoko
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have a problem with getting the list of values that exist in the list...

so in my listener >>

public void processValueChange(ValueChangeEvent comp) throws AbortProcessingException {


UIComponent source = arg0.getComponent();


<h:selectOneMenu onchange="submit()" valueChangeListener="#{testActionListener.processValueChange}" value="#{userBean.favCoffee2}">


how can I now fetch all the values there .... NOT the SELECTED value

because if the value is already there .. I dont want to add it again ...

Appreciate your help ..

Thanks.
 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Bash!

I do a lot of this lately, but I don't go mucking around in the JSF internals. Since my backing bean is supplying the SelectItem collection, I just access that collection internally.

From what the JavaDocs say, the actual SelectItems are not directly part of their associated SelectOneMenu component. So to get them, scan the SelectOneMenu's child element collection, and look for SelectItem and SelectItems objects. If you find one or more SelectItems objects, you would then have to further enumerate them in order to get the individual SelectItem objects.
 
bash bashtoko
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thanks a lot Tim for the quick reply ...

Tim .. this is what exactly I am trying to do .. is to grap this collection of the values in this component...

I ran the server in debug mode .. and couldnt find a clue to which property to look for...


could you please explain to me your way more ... ??
since the place I am trying to access the VALUES is the listener .. while the default values are in the bean ..

so how are you doing it ??

I am new here .. and I appreciate your help in advance ... please help because .. I am nearly to tear my self down !!

Thanks
 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


My SelectOneMenu has a <f:SelectItems value="#{myBean.mySelectList}"/> child element to provide the dropdown list. So internally, I can use the above code like this:

 
bash bashtoko
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again Tim ..

what if I want something like >>>

<h:selectOneMenu onchange="submit()" valueChangeListener="#{testActionListener.processValueChange}" value="#{userBean.favCoffee2}">

now how can I get all values whether selected or not

is it like this :

public void processValueChange(ValueChangeEvent arg0) throws AbortProcessingException {




HtmlSelectOneMenu selectItems = (HtmlSelectOneMenu)arg0.getComponent();

selectItems.getChildren();

???

why this method doesnt bring every value in this component ??


 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bash bashtoko wrote:
why this method doesnt bring every value in this component ??


Because the valueChangeEvent's component is the selectOneMenu control, but the SelectItems are not part of the HTMLSelectOneMenu, they're child components. Completely separte objects, one per SelectItem.
 
bash bashtoko
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


thanks a lot for your help .. and for baring me ...

but what should I do in the listener ??

I want to add a new value ... only if it does not exist ?



sorry for asking too much

thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!