• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How to determine which dataTable row was selected  RSS feed

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am very new to JSF and am having a problem. I have a dataTable where I display a button and a line of info. When the button is pressed, I want to be able to determine exactly which button was pressed so I can perform a certain action. My jsf code is:

<h:dataTable value="#{uiSelFieldList}" headerClass="tableHeader" var="fieldList">
<h:column>
<f:facet name="header">
<hutputText value="Action"/>
</f:facet>
<h:commandButton image="images/DeleteButton.gif"
action="#{projectListener.deleteUIFields}"/>
</h:column>
<h:column>
<f:facet name="header">
<hutputText value="Field Value"/>
</f:facet>
<h:inputText id="fieldValue" value="#{fieldList.fieldValue}"/>
</h:column>
</h:dataTable>
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two ways:

1) Wrap the data list in a DataModel, e.g. ListDataModel, and use DataModel#getRowData().
2) Bind the datatable to an UIData property in the backing bean, e.g. HtmlDataTable, and use UIData#getRowData().

Also see this article: http://balusc.blogspot.com/2006/06/using-datatables.html
 
Ian Dunsirn
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are there any examples of items 1 and 2 on your response anywhere? I only just started JSF programming within the last month, so I have no idea of how to carry out the solutions you have mentioned. I shall also take a closer look at the link you provided when I go to work tomorrow.
 
Ian Dunsirn
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I have this now:
<h:dataTable value="#{uiSelFieldList}" headerClass="tableHeader" var="fieldList" binding={{passData.passTable}">
<h:column>
<f:facet name="header">
<hutputText value="Action"/>
</f:facet>
<h:commandButton image="images/DeleteButton.gif"
action="#{projectListener.deleteUIFields}"/>
</h:column>
<h:column>
<f:facet name="header">
<hutputText value="Field Value"/>
</f:facet>
<h:inputText id="fieldValue" value="#{fieldList.fieldValue}"/>
</h:column>
</h:dataTable>

In my bean, I have defined passTable as an HtmlDataTable. When I try to run, I get an argument type mismatch error. What could be causing this?
 
Ian Dunsirn
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I finally figured out what you were getting at and everything seems to be five by five. Thanks for the help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!