1

I'm using primefaces 5.2 and jsf 2.2.6.

I'm trying to select a row from a datatable and populate a panelgrid. The problem is that the onRowSelect method is not being called when selecting the row.

Here is the code for the datatable:

<h:body styleClass="mainPageBody" >
<div class="projectTable">  
    <p><h:outputText value="#{msg['form.currentProjects']}" styleClass="mainPageProjectsTableTitle" /></p>
    <h:form id="formTable" >
        <p:dataTable id="transactionsTable" var="data" value="#{transactionsPage.ttList}" widgetVar="projectData" 
                     rowKey="#{data.id}"
                     draggableColumns="true" 
                     resizableColumns="true" liveResize="true" emptyMessage="#{msg['form.noTransactionsFound']}" rows="20"
                     selectionMode="single" selection="#{transactionsPage.selectedTransaction}"
                     filteredValue="#{transactionsPage.fitleredttList}" paginator="true" paginatorPosition="both" paginatorTemplate="{CurrentPageReport} {RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
                     >

            <p:ajax event="rowSelect" listener="#{transactionsPage.onRowSelect}" update="formTabs:tabs:form2:panel"/>

            <p:column id="transIdField" filterStyleClass="transIdFilter" filterBy="#{data.id}" headerText="#{msg['form.transId']}"  filterMatchMode="contains" styleClass="mainPageCompanyColumn">
                 <h:outputText value="#{data.id}"/>
            </p:column>
            <p:column id="uicNumberField" filterStyleClass="uicNumberFilter" filterBy="#{data.uicNumber}" sortBy="#{data.uicNumber}" headerText="#{msg['form.uicNumber']}"  filterMatchMode="contains" styleClass="mainPageCompanyColumn">
                 <h:outputText value="#{data.uicNumber}"/>
            </p:column>
            </p:dataTable>
    </h:form>
</div>

Here is the code for the panel that has to be populated with values from the selected row, that is part of the same page:

<h:form id="form2">
<p:growl id="msgs" showDetail="true" />
 <p:fieldset legend="Transaction details" toggleable="true" toggleSpeed="500">
    <p:ajax event="toggle" listener="#{transactionsPage.handleToggle}" update="msgs" />
    <h:panelGrid id="panel" columns="3" cellpadding="5" styleClass="ui-widget-content-borderless" columnClasses="mp-column-center">
        <ui:include src="transactionsEdit.xhtml"/>
    </h:panelGrid>
</p:fieldset>
</h:form>

The managed bean is @ViewScoped and has getter and setter method for the property selectedTransaction and also the method onRowSelect

public void onRowSelect(SelectEvent event) {
    selectedTransaction = (Transactions) event.getObject();
}

The problem is that the following code

<p:ajax event="rowSelect" listener="#{transactionsPage.onRowSelect}" update="formTabs:tabs:form2:panel"/>

is not calling the method onRowSelect.

Does somebody know what the problem could be?

EDIT:

ANSWER: It seems that I couldn't succeed with p:ajax to call the methods onRowSelect or setSelectedTransaction, even if I passed a parameter to onRowSelect.

So, I tried with f:ajax. onRowSelect was called only when passed with a parameter, but the parameter was always null. So this method wasn't useful for me, but the setSelectedTransaction is called too, so the problem solved.

And then, I had to update the panel and this is done using render for f:ajax, not update that is only used for p:ajax.

So the final ajax event call looks like this:

<f:ajax event="rowSelect" render="formTabs:tabs:form2:panel"/>
uzzi
  • 551
  • 2
  • 9
  • 29
  • Check all this: http://stackoverflow.com/questions/2118656/commandlink-commandbutton-ajax-backing-bean-action-listener-method-not-invoked – Kukeltje Feb 16 '16 at 14:09
  • Simplify your code... [mcve] and also http://www.stackoverflow.com/tags/jsf/info – Kukeltje Feb 16 '16 at 14:55
  • you are passing perimeter to onRowSelect method in bean class and in jsf page you are calling istener="#{transactionsPage.onRowSelect}" without perimeter....I think you should send rowKey value like istener="#{transactionsPage.onRowSelect(data.id)}"....I didn't try so i'm not sure but you can try.....Update only that code which is related to your issue. – Piyush Gupta Feb 17 '16 at 06:16

0 Answers0