• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Finding which cell was clicked in a DataTable?

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 >
<h:outputText 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>
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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").
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic