File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

populate selectOneMenu with list containing various type of object

 
Maciej Kawczynski
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to populate selectOneMenu with list containing various type of objects ?
For example:
List<Object>
and then during submit check what object it parsing ?

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch Maciej

Typically, we select one from *one kind* of items . so why do you want to select one from a list containing various type of objects ?

Please also look at this class http://download.oracle.com/javaee/6/api/javax/faces/model/SelectItem.html
 
Maciej Kawczynski
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your answer.

I have to make dropdown with different Object types, because i have
3 objects with almost all various fields, only id, name, price and type are the same.




i have converter for all objects.

selectOneMenu should look like this:

<h:selectOneMenu value="#{bean.object}" valueChangeListener="#{bean.listener}"
<f:selectItems value="#{bean.objects}" var="o" itemLabel="#{o.name} - #{o.type}" itemValue="#{o}"/>
<a4j:ajax event="change" render="@this"/>
</h:selectOneMenu>

And listener is not firing same like bean.object is not set while change.
Only converter for each object getAsString method is firing.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are complicated the things. why do you want to set an object as select box value/option ? *browser interpret that object as string*! and when a user select air or car and submit the form then create an appropriate object on server, if you need.
in jsp-->
<h:selectOneMenu binding="#{pc_Welcome.travelModeSelectOneMenu}"/>

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and as in your example, f:selectItems doesnt have itemLable and itemValue attribute, and instead it has value attribute which expect a collection/single of SelectItem.
additionally, f:selectItem has all the above three attribute but value attribute will take the precedence .
 
Maciej Kawczynski
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i resolved my issue, i just create base object TransportOption which has 4 fields like id, name, type, price and objects like Car, Airplane, Bus extends this object. f:selectItems populate List<TransportObtion> and now everything work very well .
Thanks all for your suggestions
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic