aspose file tools*
The moose likes JSF and the fly likes getting selected row in datatable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "getting selected row in datatable " Watch "getting selected row in datatable " New topic
Author

getting selected row in datatable

JP Estrada
Ranch Hand

Joined: Mar 21, 2006
Posts: 48
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
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16228
    
  21

Look here. It's practically magic!


Customer surveys are for companies who didn't pay proper attention to begin with.
JP Estrada
Ranch Hand

Joined: Mar 21, 2006
Posts: 48
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?
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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.


There is no emoticon for what I am feeling!
JP Estrada
Ranch Hand

Joined: Mar 21, 2006
Posts: 48
Thanks Jeff! Your suggestion works
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16228
    
  21

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

Joined: Sep 16, 2005
Posts: 1780
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

Joined: Jun 25, 2001
Posts: 16228
    
  21

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting selected row in datatable