-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: JSF DataTable, Hibernate, Updating and Deleting?
PostPosted: Thu May 01, 2008 4:51 pm 
Newbie

Joined: Thu May 01, 2008 4:30 pm
Posts: 4
I did a search and couldn't find what I was looking for. I apologize if I am rehashing anything in this question. I am a newbie at Hibernate.

I am using Hibernate 3.x. (Using it within Spring 2.0 and JSF as the presentation MVC layer)

This is the scenario:
Let's say I have a db table mapped to TbMyTable.java (and TbMyTable.hbm.xml file)

There are 2 columns in this table:
item_id int (primary key),
item_name varchar(100)

When I retrieve from the db via Hibernate, I get a List of TbMyTable objects. Then I do whatever I need to display the List on the JSP, in this specific case, I am using a JSF dataTable. Great so far.

Let's say the item_name column is editable in the JSP. So the user goes down the list of items on the page and starts to edit some of the data in item_name column. Let's say out of the 10 rows, the user changed 3 of them. The changes are reflected in the List I have stored in the session scoped bean. The user then clicks the save button.

Question:
Is there any way to "detect" the 3 rows that were changed and issue updates on them as opposed to going through the entire 10 rows one by one and issuing a saveOrUpdate()?

Any help is much appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 02, 2008 1:46 am 
Beginner
Beginner

Joined: Fri Apr 11, 2008 1:48 am
Posts: 36
You are using an HTMLDataTable on the managed bean side or?
You can access to the actual row with this command:

TbMyTable actTb = (TbMyTable) this.getDataTable().getRowData();

If you get an error message, the datatable has even an method for the rowId. With that id, you can get the item from your TbMyTable List.

Hope this helps? Pls don't forget to rate...


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 02, 2008 10:32 am 
Newbie

Joined: Thu May 01, 2008 4:30 pm
Posts: 4
Yes I am, via the <binding> property of the dataTable in the jsp.
I am aware that I can access the actual row, put some kind of action in my backing bean that gets called everytime something happens to the row, etc.

However, that means a roundtrip to the server each and every time right? I was hoping to avoid that.

So I was thinking the user will make changes in the dataTable in the jsp, then they will hit the "Save" button which then will call a method that will actually do the saving. The save method will iterate through the dataTable List and issue a hibernate save each time it iterates.

Is that a typical thing to do when trying to update rows like this?



thinkpad wrote:
You are using an HTMLDataTable on the managed bean side or?
You can access to the actual row with this command:

TbMyTable actTb = (TbMyTable) this.getDataTable().getRowData();

If you get an error message, the datatable has even an method for the rowId. With that id, you can get the item from your TbMyTable List.

Hope this helps? Pls don't forget to rate...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.