0

I have upgraded my application from primefaces 3.4.2 to primefaces 5.1 and JSF 2.1.10 to 2.1.29 version.My below logic use to work with old jars but after upgrade its showing unexpected behaviour.

I have a commandLink which loads a dialog box onclick() event.Dialog box contains dynamic data table which will be populated by preLoadMethod in bean.

Before upgrade to new jars on click of commandLink the dialog box displays the search results in dynamic table properly with no issues.After upgrade to new jars dialog box displays "No records found." message instead of search results on click of commandLink.I have checked that data is available at client side by entering some value in filter box which shows the filtered data and after removing the filtered value I can see the complete search results.When I closed the dialog box and then again click the commandlink I can see the search results in the datatable and then after some seconds the content will be refreshed and it shows the message "No records found".

    1)xhtml code....

<html>
....
....
<h:body>
....
<h:form>
...
<h:panelGroup id="panelGroupId">
   <p:commandLink id="searchId" onclick="dialogVar.show()" process="@this" global="false" 
   action="#{bean.preLoadMethod}" update="@none">
   <f:setPropertyActionListener target="#{bean.selectedSearchId}" value="7" />
   <f:setPropertyActionListener target="#{bean.componentId}" value="ipComponent:searchForm_7:resultsTable" />
   <h:graphicImage styleClass="rollover imgAligntop" style="border:0;" name="search_on.png" library="images" />
   </p:commandLink>
   <p:tooltip for="panelGroupId" value="Search"></p:tooltip>
</h:panelGroup>
...
</h:form>
.....
<p:dialog id="dialogId" hideEffect="fade" modal="true" widgetVar="dialogVar" resizable="false"  appendTo="@(body)" 
   position="230,120" draggable="true" minimizable="false" maximizable="false" header="Dialog"> 
   <custom:searchComponent id="ipComponent" dialogName="searchDialog" searchId="7">
   </custom:searchComponent>
   <p:ajax event="close" listener="#{bean.closeDialog}" global="false"/>
 </p:dialog>
...
</h:body>
</html> 

2)Bean code

public void preLoadMethod() {
   //Gets the data from database and populates the List(searchDataList,filteredResults,columns) 
   which will be used by datatable to populate

   FacesContext facesContext = FacesContext.getCurrentInstance();
   DataTable dynamicDataTable = (DataTable) facesContext.getViewRoot().findComponent(componentId+"_"+selectedSearchId);
   if(dynamicDataTable != null) {
      lovDataTable.setEmptyMessage("No records found.");
   }

   RequestContext context = RequestContext.getCurrentInstance();
   String arr[] = {componentId+"_"+selectedSearchId};
   Collection<String> updateFields = Arrays.asList(arr);
   whereClause = "";
   context.update(updateFields);         
}

3)searchComponent.xhtml

<html>
....
...
<composite:interface.....
<composite:attribute name="searchId" required="true" />

</composite:interface>
<composite:implementation>

<h:form id="searchForm_#{cc.attrs.searchId}" onsubmit="return false;">  

----

<p:dataTable id="resultsTable_#{cc.attrs.searchId}" var="search" paginator="true" rows="10" value="#{bean.searchDataList}"
   selectionMode="single" pageLinks="5" paginatorPosition="both" rowIndexVar="rowIndexVar"
   paginatorTemplate="Page {CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
   paginatorAlwaysVisible="true"       
   filteredValue="#{bean.filteredResults}"
   widgetVar="searchTable_#{cc.attrs.searchId}"
   emptyMessage="Data is loading please wait...">

   <p:columns id="searchColumns" value="#{bean.columns}" var="column" sortBy="#{search[column.property]}"
   filterBy="#{search[column.property]}"
   rendered="#{fn:length(bean.searchDataList) gt 0}"
   filterMatchMode="startsWith"
   >
   <f:facet name="header">
   #{column.header}
   </f:facet>

   <h:outputText value="#{search[column.property]}" id="searchText" >

   </h:outputText>
   </p:columns>
</p:dataTable>
----
</h:form>   
---
</composite:implementation>
</html>
priya
  • 361
  • 1
  • 4
  • 18

2 Answers2

1

The issue is with filteredValue reference in backing bean.I was setting the values to this reference in bean.But don't know why this was working fine before PF 5.1 version.

Bean code

private List filteredResults = new ArrayList();
---
public void preLoadMethod() {
  //Gets the data from database and populates the List(searchDataList,filteredResults,columns) 
   which will be used by datatable to populate
   searchDataList = //Populate from database;
   filteredResults=searchDataList;

   FacesContext facesContext = FacesContext.getCurrentInstance();
   DataTable dynamicDataTable = (DataTable) facesContext.getViewRoot().findComponent(componentId+"_"+selectedSearchId);
   if(dynamicDataTable != null) {
      lovDataTable.setEmptyMessage("No records found.");
   }

   RequestContext context = RequestContext.getCurrentInstance();
   String arr[] = {componentId+"_"+selectedSearchId};
   Collection<String> updateFields = Arrays.asList(arr);
   whereClause = "";
   context.update(updateFields);   

}

I have now just provide the filteredValue reference with null value in bean and getter/setter method.Now its working fine.

Bean code

private List filteredResults = null;

   public List getFilteredResults() {
      return filteredResults;
   }

   public void setFilteredResults(List filteredResults) {
      this.filteredResults = filteredResults;
   }
priya
  • 361
  • 1
  • 4
  • 18
0

Inside your commandLink searchId use oncomplete instead of onclick and try it again.

You also could change from action to actionListener.

To learn more read this post.

Community
  • 1
  • 1
giaffa86
  • 708
  • 1
  • 9
  • 22
  • I have changed onclick to oncomplete but still it didn't solve the issue.Also used actionlistener with oncomplete but it didn't solve the issue. I have also observed that when I click commandLink and then after a second again click the command link then I will get the search results in datatable in dialog box that means sending request twice to bean(preLoadMethod). – priya Dec 18 '14 at 10:47
  • It got solved by removing the datatable attribute "filteredValue" but I dont know why this attribute causing issue in PF5.1. – priya Jan 12 '15 at 07:35