onRowSelect of radiobutton in Primefaces datatable

17,789

Solution 1

There is no such attribute rowSelectListener in Primefaces 3.4.2

Use <p:ajax event="rowSelect" instead , like in the showcase

For radio/checkbox etc... these are the available <p:ajax event

  • rowSelectRadio
  • rowSelectCheckbox
  • rowUnselectCheckbox
  • rowDblselect

See the showcase (search for p:ajax on the page) DataTable - Selection

Solution 2

For older version of Primefaces.

         <p:dataTable id="updateBanData"
                                 var="banSummary"
                                 value="#{sponsorBanMBean.sponsorBanForm.banSummaries}"
                                 styleClass="appTbl"
                                 selection="#{sponsorBanMBean.sponsorBanForm.selectedBanSummary}"
                                 emptyMessage="#{msgs.noRecordsFound}" selectionMode="single"
                    >



        <p:ajax event="rowSelect" listener="#{sponsorBanMBean.onUpdateBanRowSelect}"
                                update="updateSponsorShipBanDetailPanel"/>
    </p:p:dataTable>

     <p:outputPanel id="updateSponsorShipBanDetailPanel">
show your selection details. 

    </p:outputPanel>

Java Code Inside Manged Bean.

    public void onUpdateBanRowSelect(SelectEvent selectEvent) {
            logger.logMethodStartAsDebug();
            BanSummary selectedBanSummaryEvent = (BanSummary) selectEvent.getObject();

            if(selectedBanSummaryEvent != null){
                sponsorBanForm.setUpdateSponsorShipBanDetail(true);
            }
            logger.logMethodEndAsDebug();
        }
Share:
17,789

Related videos on Youtube

Jacob
Author by

Jacob

Downvote, at no time in the past or hitherto; not ever.

Updated on October 03, 2022

Comments

  • Jacob
    Jacob over 1 year

    I have a datatable using JSF2.0 where I have rows displayed with radiobutton

    <p:dataTable id="dataTable" var="emp" lazy="true" value="#{req.lazyModel}"
                paginator="true" rows="10" 
                paginatorTemplate="{CurrentPageReport}  
                        {FirstPageLink} {PreviousPageLink} 
               {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
           rowsPerPageTemplate="5,10" 
               selection="#{req.selectedEmp}"
                rowKey="#{req.empNo}" 
           rowSelectListener="#{req.onRowSelect}">
    
    
     <p:column selectionMode="single" style="width:18px" />
    

    and in Bean I have

    public void onRowSelect(SelectEvent event) { 
           System.out.println("row "+((Request) event.getObject()).getEmpNo());  
    
        } 
    

    However onRowSelect method is not getting invoked. What could be the reason for this?

    My idea of radiobutton is when user clicks radiobutton, I would like to display a datatable below the master datatable with details of selected row.

    Any help is highly appreciated.

    Update 1

    <p:dataTable id="dataTable" var="emp" lazy="true" value="#{req.lazyModel}"
                paginator="true" rows="10" 
                paginatorTemplate="{CurrentPageReport}  
                        {FirstPageLink} {PreviousPageLink} 
               {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
           rowsPerPageTemplate="5,10" 
               selection="#{req.selectedEmp}">
    
    
     <p:column selectionMode="single" style="width:18px" />
     <p:ajax event="rowSelect" listener="#{reqMB.onRowSelect}" />