• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How to determine which dataTable row was selected

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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">
<h:outputText value="Action"/>
</f:facet>
<h:commandButton image="images/DeleteButton.gif"
action="#{projectListener.deleteUIFields}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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">
<h:outputText value="Action"/>
</f:facet>
<h:commandButton image="images/DeleteButton.gif"
action="#{projectListener.deleteUIFields}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic