Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Help with h:selectOneMenu

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 28054
198
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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 28054
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 28054
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic