This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSF and the fly likes Finding which cell was clicked in a DataTable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Finding which cell was clicked in a DataTable?" Watch "Finding which cell was clicked in a DataTable?" New topic
Author

Finding which cell was clicked in a DataTable?

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 388
I have rows that have cells with links to another page. I need to find out which individual cell link was clicked. I know I can find which row was clicked by binding a HtmlDataTable object to the DataTable on the form. But I need to know which cell in the row was clicked. Any ideas?

tableDataList is the list of row objects

cellDataList is the cells in each row object



<h:dataTable id="idViewTable"
value="#{IndexHandler.tableDataList}"
var="rowData"
border="0" cellpadding="1" cellspacing="1" width="100%">
<h:column >
<hutputText value="#{rowData.rowName}"/>
</h:column>
<h:column >
<h:commandLink actionListener="#{IndexHandler.callBasicPopupWindow}"
value="#{rowData.cellDataList[0].name}"/>
</h:column>
<h:column >
<h:commandLink actionListener="#{IndexHandler.callBasicPopupWindow}"
value="#{rowData.cellDataList[1].name}"/>
</h:column>
<h:column >
<h:commandLink actionListener="#{IndexHandler.callBasicPopupWindow}"
value="#{rowData.cellDataList[2].name}"/>
</h:column>
<h:column >
<h:commandLink actionListener="#{IndexHandler.callBasicPopupWindow}"
value="#{rowData.cellDataList[3].name}"/>
</h:column>
<h:column >
<h:commandLink actionListener="#{IndexHandler.callBasicPopupWindow}"
value="#{rowData.cellDataList[4].name}"/>
</h:column>

</h:dataTable>
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Not possible. You could consider to attach a f:attribute to the h:commandLink where in you specify the column identifier. The attribute value on its turn can be obtained by actionEvent.getComponent().getAttributes().get("attributename").
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Inject the datamodel into a backing bean for the target page, then use the get selected row method on it.

For non-JSF target pages, one of the options available is to keep a key (such as the row number) as a column in the datamodel and supply it as a commandLink parameter.


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

Joined: Oct 08, 2006
Posts: 2458
Tim Holloway wrote:Inject the datamodel into a backing bean for the target page, then use the get selected row method on it.

For non-JSF target pages, one of the options available is to keep a key (such as the row number) as a column in the datamodel and supply it as a commandLink parameter.

He was not asking how to find the row object in question (he mentioned he already know how to do it), but how to find the column in question. He is using the same commandlink action in every column.
 
 
subject: Finding which cell was clicked in a DataTable?