wood burning stoves 2.0*
The moose likes JSF and the fly likes how to delete a row from a 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 delete a row from a datatable?" Watch "how to delete a row from a datatable?" New topic
Author

how to delete a row from a datatable?

Mark Moge
Ranch Hand

Joined: Mar 14, 2009
Posts: 96

Hi.
I want to delte row from the dataTable. I have a java class called Book and the datatable on jsp page. How can I write a delete method? Can you tell me how to get an IdBook from the table (when I get id I will be able to delete the correct row from the database). Or maybe you have a better idea.




SCJP6 | http://programmerutilities.blogspot.com/
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16101
    
  21

The DataTable is only a View component for a DataModel. The DataModel is the backing data for the view, and isn't supposed to actually be the Domain Model. In fact, at best, it can only wrap a Domain Model.

In order to "delete a row from a datatable", therefore, you must remove it from the DataModel. You MAY also choose to remove it from the Domain Model (that is, delete the row from the database), but that's up to you. If the DataModel doesn't contain the row, the row won't display. Conversely, you can include rows in the DataModel that aren't necessarily in the Domain model, since you're the one that determines the difference.


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

Joined: Mar 14, 2009
Posts: 96

I have solved my problem by binding the datatable with a HtmlDataTable.

then in the book class

and after that i could get data from a selected row by using
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16101
    
  21

Er, you do realize that that just retrieves the row and doesn't actually delete it, don't you?
Mark Moge
Ranch Hand

Joined: Mar 14, 2009
Posts: 96

Tim Holloway wrote:Er, you do realize that that just retrieves the row and doesn't actually delete it, don't you?

Yes I do.
With data from a row I have an id of a book so I can write a SQL query to delete this book from a database.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16101
    
  21

Just checking.

Ironically enough, I'm coding almost that exact same sequence myself right now. I'm working on a generic database table editor for a client, since I couldn't seem to find any viable ones in open source. If I'm not too revolted by the final results, you may see it on SourceForge someday soon.
 
GeeCON Prague 2014
 
subject: how to delete a row from a datatable?