Get selected item when double clicking on a Richfaces extendedDataTable in JSF2

最后都变了- 提交于 2019-12-02 14:56:38

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!