Forums Register Login

how to delete a row from a datatable?

+Pie Number of slices to send: Send
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.



+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Er, you do realize that that just retrieves the row and doesn't actually delete it, don't you?
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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.
This tiny ad is wafer thin:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 4261 times.
Similar Threads
problem with datatable binding attribute
jsf and database connection problem
commandButton in dataTable doesn't work -method not found
Displaying h:columns in different rows
JSF h:dataTable Question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:09:56.