• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting selected row in datatable

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

How do i get the index of the selected row in a datatable using a selectBooleanCheckBox?

Right now i don't have an idea..

Thanks
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look here. It's practically magic!
 
JP Estrada
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim. But my case scenario is i have a datatable, and each row has a selectbooleanCheckbox. What should happen is that all the rows with the selected checkbox will be displayed on the next page...

How do i do this?
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not have the bean class that represents a row have a boolean property like selected? Then you could simply map the check box to the selected property. I used to make my business classes militantly business-oriented -- "being selected is a GUI issue, not a business issue", but I haven't noticed bad things happening since a relaxed that. If you can't change your business bean, you could have add a GUI wrapper:

Then when mapping a column, you would map the flavor column to "#{x.gum.flavor}" and the selected column to "#{x.selected}". If the gum and the wrapper were collapsed to one class, these mappings would be "#{x.flavor}" and "#{x.selected}". Either way, it works.
 
JP Estrada
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jeff! Your suggestion works
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only downside I've seen is when I tried to directly wire JDO beans into the array. The database in question was one that didn't have a boolean primitive type, so the JDO mapper made the boolean fields integers, instead and the JSF checkboxes wouldn't connect to them. Ended up making a transfer object that was almost field-for-field duplication of the JDO object except on the booleans.

If anyone has a quick, clean way to handle that, I'd be glad to learn it.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sounds more like a JDO question. If you were going POJO with Hibernate, say, the property could stay boolean (which is logically what it should be) and the persistence framework would handle the mismatch between that and the database field, perhaps forcing you to write some custom code for the mapping if you need it.
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can make JDO handle the mapping in roughly the same way that Hibernate does. I'd rather not, however, since that requires me to touch stuff that's initially generated for me and I prefer not to customize generated artifacts since the customizations get nuked if I regenerate.
 
reply
    Bookmark Topic Watch Topic
  • New Topic