aspose file tools*
The moose likes JSF and the fly likes How to determine which dataTable row was selected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to determine which dataTable row was selected" Watch "How to determine which dataTable row was selected" New topic
Author

How to determine which dataTable row was selected

Ian Dunsirn
Ranch Hand

Joined: May 25, 2006
Posts: 36
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>
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
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

Joined: May 25, 2006
Posts: 36
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

Joined: May 25, 2006
Posts: 36
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

Joined: May 25, 2006
Posts: 36
Ok, I finally figured out what you were getting at and everything seems to be five by five. Thanks for the help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to determine which dataTable row was selected
 
Similar Threads
boolean property in dataTable
JSF + RichFaces not able to reRender
JSF datatable doubt
Unable to display header in outer JSF datatable of a nested datatable using facet tag
passing parameters from JSF to Java class and JSF to JSF