wood burning stoves 2.0*
The moose likes JSF and the fly likes How to display a list of strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to display a list of strings " Watch "How to display a list of strings " New topic
Author

How to display a list of strings

Fred Funks
Greenhorn

Joined: Mar 07, 2014
Posts: 10

I have figured out, how to diplay basic datatypes of an entity / object in a dataTable, but I can't find a way to display a List<String>.

I also tried it with ui:repeat, but the space, where it should appear, stays empty. This is my code right now:

Product.java (the entity)


and the page: index.xhtml



This is probably not very hard to do, but there are somehow no good examples on the internet for this.

Thank you in advance!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16160
    
  21

I think you're mis-using the term "datatype". In the case of rows of a dataTable, what you seem to be calling its "datatypes" would actually be the values of the row item's properties. For the list, there are no properties as such, so it's simple the list values you want to display.

I cannot think offhand why what you are proposing wouldn't work as long as the neededResources property of Product was populated with list values. Although it's generally not possible to make an ORM model object serve directly as a JSF backing bean GUI model object, since the JSF bean manager doesn't have the ability to either locate a specific persistence model object instance or to retrieve it and map it.

One thing I do recommend is that instead of a simple EL expression to output the value, use the h:outputText element. It won't solve the problem of getting a value, but it will at least allow JSF to more cleanly integrate that value into its component tree. Plus, of course, add support for stuff like CSS styling.


Customer surveys are for companies who didn't pay proper attention to begin with.
Fred Funks
Greenhorn

Joined: Mar 07, 2014
Posts: 10

Tim Holloway,

thank you for your reply. Sorry, that I answer only now.

As i suspected, the way I tried to display the list of strings was right. What I didn't know, is that such a list of an entity-class doesn't get loaded automatically, when an instance of that class does. So, I set the fetchType of that list to 'Eager' and now it gets displayed on my page :)
 
 
subject: How to display a list of strings