• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get selected records from Data Table in JSF

 
Ram Chhabra
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am making datatable in JSF using h:dataTable tag.

I am having several rows in that with checkbox in front of every record.

How can i get that which record is selected when user submit the page.

Thanks
Ram
 
Tom Fulton
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on how you have configured the checkbox to select the item within the datatable. I have used two different approaches. In the first, the checkbox is bound to a UISelectBoolean instance in the backing bean, like this:



The backing bean method would iterate through the elements of the datatable, and the UISelectBoolean instance would be set when you hit a row that is selected:



Frankly, this is not intuitive to many people...the value of the instance changes dynamically (because it is bound) as you iterate through the values in the datatable data. The second approach is the connect the checkbox to an boolean value of the backing bean. You have to get the entire row of data in a bean, then look at the value of that data member. Here is the declaratiion of the checkbox:



And here is the code within the backing bean:



Sorry for the lengthy reply...I hope this helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!