File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes datatable row id Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "datatable row id" Watch "datatable row id" New topic

datatable row id

bruce truong

Joined: Mar 14, 2011
Posts: 12
Hello all,

I googled all day long but cannot find how to add the row id to a JSF datatable. Row id is made up of user's ID. I would like to basically create <tr id=123456>. Can someone point me to the right direction?

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

The JSF/xml "id" attribute isn't really a good place to store data. It's not intended for that purpose. Among other things, you might have noticed that it's not legal to use EL to substitute in an id value.

If it's really required to place a key value such as userid in a row in a dataTable and you don't want it visible, you can put it in a hidden text field. But chances are that you are really just trying to know which row was selected when you click on a button or link in the dataTable.

If that's the case, you're over-complicating things. An action method fired by a control in a dataTable can simply call getRowData() on the backing datamodel object to get the row object that backs that particular row. Or use getRowIndex() to get the index of the row.

Because of this mechanism, you don't actually even need to put the record ID out on the webpage at all unless you want to. When the action is fired, any user changes on the web form will have been pushed into the datamodel's row object, and you'll know which row it was, so it's then a trivial matter to scoop up that data and write it out to the database or do whatever else you want to do with it.

An IDE is no substitute for an Intelligent Developer.
bruce truong

Joined: Mar 14, 2011
Posts: 12
Thank you for the enlightenment. I have lots to learn.

I agree. Here's the link:
subject: datatable row id
It's not a secret anymore!