Datatable RowSelect Event Surface

I have the following in my xhtml

<h:form id="clientTableForm" prependId="false"> <p:dataTable id="clientTable" widgetVar="clientTableVar" var="client" value="#{resendEmailController.lazyDataModel}" paginator="true" rows="15" paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {CurrentPageReport}" rowsPerPageTemplate="5,10,15,20,25,50,75,100" paginatorPosition="bottom" pageLinks="5" lazy="true" sortBy="#{client.cclnCode}" sortOrder="ascending" selection="#{resendEmailController.selectedClient}" selectionMode="single" filterDelay="500" scrollable="true" scrollHeight="380"> <p:ajax event="rowSelect" listener="#{resendEmailController.changeClient}" update="_accountTableForm_accountTable" /> <p:column id="cclnCodeColumn" headerText="Client Code" style="width:25%;" sortBy="#{client.cclnCode}" filterBy="#{client.cclnCode}" filterMaxLength="10"> <h:outputText value="#{client.cclnCode}" converter="#{trimStringConverter}" /> </p:column> <p:column id="cclnNamenColumn" headerText="Client Name" style="width:75%" sortBy="#{client.cclnName}" filterBy="#{client.cclnName}" filterMaxLength="50"> <h:outputText value="#{client.cclnName}" converter="#{trimStringConverter}" /> </p:column> </p:dataTable> </h:form> </p:layoutUnit> <script type="text/javascript"> $(document).ready(function() { autoSelectClient(); }); function autoSelectClient() { if (clientTableVar.isEmpty() == false) { clientTableVar.selectRow(1, false); } } </script> 

And I have it in my support bean

  public void changeClient(SelectEvent selectEvent) { ResendEmailClient client = (ResendEmailClient) selectEvent.getObject(); selectedClient = client; String cclnCode = client.getCclnCode(); selectedAccounts = getService().listAccounts(cclnCode); } 

I would just like to ask why the variable "selectedClient" in the backup bean is NULL when "autoSelectClient ();" is executed. But if I clicked the line, "selectedClient" is already set.

As you can see in my bean support, I can get the value I want by getting the object inside the SelectEvent, but I just want to know what the difference is.

Also, if possible, you can also suggest how to replicate the emulated second script so that "selectedClient" is already set before calling "changeClient ()".

Using JSF 2.1 PrimeFaces 3.5 Mojarra 2.1

+4
source share
1 answer

try sending your datatable id during your ajax select event as follows:

 <p:ajax event="rowSelect" listener="#{resendEmailController.changeClient}" update="_accountTableForm_accountTable" process="clientTable" /> 

Because when you trigger your event, the real situation of your choice is not sent.

+6
source

Source: https://habr.com/ru/post/1483259/


All Articles