File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to delete a row from a datatable?

 
Mark Moge
Ranch Hand
Posts: 100
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



 
Tim Holloway
Saloon Keeper
Pie
Posts: 17622
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mark Moge
Ranch Hand
Posts: 100
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17622
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Er, you do realize that that just retrieves the row and doesn't actually delete it, don't you?
 
Mark Moge
Ranch Hand
Posts: 100
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17622
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic