onRowSelect of radiobutton in Primefaces datatable
Asked Answered
M

2

6

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}" />  
Marlette answered 25/12, 2012 at 7:48 Comment(2)
Your PrimeFaces version looks ancient, what is it?Casiano
@CagatayCivici I am using Primefaces 3.4.2.Marlette
F
18

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

Forestay answered 25/12, 2012 at 10:9 Comment(18)
Thanks Daniel for pointing it out. When I use selectionMode="single" without <p:column selectionMode="single" style="width:18px" /> , then I could println statement in onRowSelect method. However if I use <p:column selectionMode="single" style="width:18px" />, then nothing is printed in onRowSelect method. I have included the code as update 1 in my question.Marlette
then try to use <p:ajax event="rowSelectRadio"Forestay
I tried <p:ajax event="rowSelectRadio" listener="#{reqMB.onRowSelect}" /> , but no use. onSelectRadio doesn't seems to support.Marlette
I am using Hibernate 4, Spring 3 and JSF 2.0Marlette
I tried rowSelectRadio, but cannot get the prinln statement working in onRowSelect method.Marlette
do you have any exceptions ? how about some simple System.out.println("1 2 3"); ?Forestay
No exceptions and System.out.println("1 2 3"); doesn't print. I am using lazy loading and datamodel is extended with LazyDataModel.Marlette
dunnoo... try with rowKey="#{req.empNo}" in your tableForestay
I have added that as well, but no luck. I have put a wrong method like listener="#{req.onRowSelectWrongMethod}" in <p:ajax, however it didn't throw any errors.Marlette
+1 for rowSelectRadio, been searching it for hoursGerlac
hi @Forestay , stuck on the same issue how can I fire the event on select of <p:column selectionMode="single" /> .. not working for meJamilla
@Rishi, adding <p:ajax event="rowSelect" to your <p:dataTable should work, like in the Update 1 in the original question...Forestay
<p:column selectionMode="single" ></p:column> <p:ajax event="rowSelect" listener="#{managePatientTO.rowSelect}" update="siteTable" /> and public void rowSelect(SelectEvent event) { System.out.println(">><<>>"); } still not working @ForestayJamilla
@Rishi, Is you table wrapper by h:form ? If it is wrapped and its not working you better post a new question with all the relevant details...Forestay
@Forestay not wrapped in <h:from but why we use in primefaceJamilla
@Rishi , your table must be wrapped in h:form , you can't use any ajax/basic submits unless its inside a h:formForestay
1 for rowSelectRadio, Work for meGormley
If I could, I would upvote this every time, I landed here. Thank you!Ilise
B
1

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();
        }
Breezy answered 14/4, 2017 at 17:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.