In my JSF 2 application I have a Richfaces extendedDataTable. When I doubleclick on a row I want to leave this page and I will display the details of the selected table entry on this other page. I tryied the following in the table page:
<rich:extendedDataTable
value="#{bean.loadedAnfragen}" var="anfrage"
selection="#{bean.selectedAnfrage}" id="anfragenTable"
selectionMode="single"
onrowdblclick="showAnfrage();">
... here are my columns ...
</rich:extendedDataTable>
<a4j:jsFunction name="showAnfrage" action="#{bean.showAnfrage}" />
The method in the bean gets called but the selection (the row where I double clicked) is null. This is the code for the appropriate method:
public void showAnfrage() {
UIExtendedDataTable table = ( UIExtendedDataTable )FacesContext.getCurrentInstance().getViewRoot().findComponent( "mainForm:anfragenTable" );
if( table != null ) {
for( Object selection : table.getSelection() ) {
System.out.println( "Thats the selected object: " + selection );
}
}
}
I also tried some ajax stuff. I wanted to pass the selection with f:setPropertyActionListener
inside an a4j:ajax
tag but this is impossible because the datatable itself is no action source so the setPropertyActionListener tag cannot be called.
Doeas anyone has a solution for getting the selected item after doubliclicking the extendedDataTable row?
I have implemented it with onrowclick:
<a4j:jsFunction name="selectRow" action="#{chAction.selectClient}">
<a4j:param name="selectedClientId" assignTo="#{chAction.selectedClientId}" />
</a4j:jsFunction>
<rich:dataTable id="chTable"
rows="#{referenceData.recordsPerPage}" style="width: 100%"
value="#{chAction.clients}" var="res" sortMode="single"
rowClasses="oddrow, evenrow"
onrowclick="selectRow('#{res.clientId}')"
rowKeyVar="currRow" >
You can change event to double click.
来源:https://stackoverflow.com/questions/20885535/get-selected-item-when-double-clicking-on-a-richfaces-extendeddatatable-in-jsf2