Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to display Hibernate Set to JSF Datatable

 
Ron De Leon
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSF datatable does accept objects with type Collection. What is the error you are getting?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18160
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to make sure... You are wrapping the collection with a JSF model, aren't you?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an excellent explanation about using datatables.
 
Ron De Leon
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just convert it to a List or a DataModel. Simply put it in the constructor of a subclass.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18160
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This indeed is a good practice.
 
Akaine Harga
Ranch Hand
Posts: 99
Java MyEclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Samuel March
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Akaine Harga
Ranch Hand
Posts: 99
Java MyEclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic