• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

How to get selected records from Data Table in JSF

Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic