• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Finding which cell was clicked in a DataTable?

 
M Burke
Ranch Hand
Posts: 406
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18367
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic