Meaningless Drivel is fun!
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
JavaRanch » Java Forums » Java » JSF
Bookmark "How to display a list of strings " Watch "How to display a list of strings " New topic

How to display a list of strings

Fred Funks

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: (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: 17410

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.

An IDE is no substitute for an Intelligent Developer.
Fred Funks

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 :)
I agree. Here's the link:
subject: How to display a list of strings
jQuery in Action, 3rd edition