File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes JSF: Show me a better way Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "JSF: Show me a better way" Watch "JSF: Show me a better way" New topic

JSF: Show me a better way

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286

I am filling list boxes with data from a database. Nothing new there. But it seems really messy the way I am doing it now. I have a list that holds a list of hardware items (motherboard, harddrive, etc). I am using Hibernate so this is my method to retrieve my list:

This return a java.util.List of Hardware objects. I return that list to one of my backing beans and in order to fill the list I have this method:

And then in my JSF page

My getHardwareList method is the nastiest thing I have seen in a while. Is there a better way to do this?

GenRocket - A Test Data Generation Platform
Dave Wood
Ranch Hand

Joined: Aug 02, 2004
Posts: 161
I think that's pretty much what you need...though it might be a bit less ugly like this...

or, better yet, in Tiger:

Co-Author of <a href="" target="_blank" rel="nofollow">Java Swing</a><br />Co-Creator of <a href="" target="_blank" rel="nofollow">SCJP 5.0</a> and <a href="" target="_blank" rel="nofollow">SCJA</a> exams
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286

Thanks Dave. I will give that a shot. The Tiger way looks best to me.
I agree. Here's the link:
subject: JSF: Show me a better way
Similar Threads
problem while setting default value for h:selectOneMenu
Dropdown creation dynamically from DB lookup
DropDown Menu error in Struts 2
JSF drop down.
How to set default selection for selectOneMenu?