wood burning stoves 2.0*
The moose likes JSF and the fly likes How to display Hibernate Set to JSF Datatable 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 Hibernate Set to JSF Datatable" Watch "How to display Hibernate Set to JSF Datatable" New topic
Author

How to display Hibernate Set to JSF Datatable

Ron De Leon
Greenhorn

Joined: Feb 14, 2006
Posts: 11
Hi,

I am using Hibernate to retrieve data, and it giving me a Hibernate Set. I tried to used this Set in JSF datatable but I am keep getting error.

Does anyone know how to make JSF datatable to accept any type of Collection?

Or any other solutions?

Thanks,
Ron
Eugene Abarquez
Ranch Hand

Joined: May 18, 2006
Posts: 211
The JSF datatable does accept objects with type Collection. What is the error you are getting?


There's so much to learn in this industry, and not everybody has the necessary interest.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Just to make sure... You are wrapping the collection with a JSF model, aren't you?


Customer surveys are for companies who didn't pay proper attention to begin with.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Here is an excellent explanation about using datatables.
Ron De Leon
Greenhorn

Joined: Feb 14, 2006
Posts: 11
Hi Guys,

Thanks for the replys. I am using MyEclipse to create hibernate beans base on the database. It creates me a set of abstract, concrete and DAO classes.


For example, were is the full constructor of concrete class for hibernate:

public CompUser(Integer idUser, BusinessGroup businessGroup, UserRole userRole, String ntUsername, String nmFirst, String nmLast, String phone, String email, Integer indActive, Date dtCreated, Date dtModified, String idUserLastModified, String nmMiddlee, String nmSuffix, Date dtLastLogin, Integer indAdminReview, Set idUserReferences, Set accounts, Set userFeedbacks) {

My problem is that when I what to getAccounts(). It returns me a Hibernate Set object, not a list.

So how can I iterate a Hibernate Set in a List in Datatable.

Thanks,
Ron
Ron De Leon
Greenhorn

Joined: Feb 14, 2006
Posts: 11
sorry
couple of typo error:

1. For example, HERE is the full constructor of concrete class for hibernate:

2. My problem is that when I want to getAccounts().
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Just convert it to a List or a DataModel. Simply put it in the constructor of a subclass.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Speaking just in abstract terms, a Set isn't an ordered collection, but a display of a collection on a page will be - even if only geometrically. So it's not unreasonable to be required to convert to an ordered collection before rendering.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
This indeed is a good practice.
Akaine Harga
Ranch Hand

Joined: Nov 03, 2009
Posts: 79

I know this thread is old, but it explains my current problem perfectly.

Since I have entity beans declared as managed beans I can't just change Set declarations and their getters to List.
So what's the suggestion?


Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?
willCodeForFood("Java,PHP,C#,XML,VBS,XHTML,CSS,JavaScript,SQL"); //always looking for job opportunities in AU/NZ/US/CA/Europe :P
Samuel March
Ranch Hand

Joined: Oct 28, 2009
Posts: 39
public interface Set extends Collection
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Set.html





or just always without any hooha



or with hooha



...did you have the fish?!............................ No.
Akaine Harga
Ranch Hand

Joined: Nov 03, 2009
Posts: 79

Mmm, perhaps I asked the question badly.

I know how to convert set to list or collection. Btw there is a much easier way to do this: just by using the corresponding constructors:

The situation is that my entities are declared as managed beans. So I do not have an intermediate cap between front and back. The database structure demands usage of Set while JSF can't inject directly into the entity variables because of the unsupported type. So I was looking for a way to cast/convert Set there and back to solve the conflict with JSF. Maybe by using a converter or some annotation...
 
jQuery in Action, 2nd edition
 
subject: How to display Hibernate Set to JSF Datatable