This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Finding which cell was clicked in a DataTable?

 
M Burke
Ranch Hand
Posts: 401
  • 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
Pie
Posts: 18009
47
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