primefaces5.1-commandLink操作和onclick不同步

时间:2014-12-17 11:14:09

标签: jsf jsf-2 primefaces

我已经将我的应用程序从primefaces 3.4.2升级到primefaces 5.1和JSF 2.1.10到2.1.29版本。我的逻辑用于使用旧jar,但升级后显示出意外的行为。

我有一个commandLink,它加载一个对话框onclick()event.Dialog框包含动态数据表,该表将由bean中的preLoadMethod填充。

在点击commandLink升级到新罐之前,对话框正确显示动态表中的搜索结果,没有任何问题。升级到新罐后,对话框显示"未找到记录。"单击commandLink时,消息而不是搜索结果。我通过在过滤器框中输入显示过滤数据的值来检查客户端的数据是否可用,并且在删除过滤后的值后,我可以看到完整的搜索结果。当我关闭时对话框,然后再次单击命令链接我可以在数据表中看到搜索结果,然后在几秒钟后内容将刷新并显示消息"没有找到记录"。

    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>

2 个答案:

答案 0 :(得分:1)

问题在于支持bean中的filteredValue引用。我在bean中将值设置为此引用。但是不知道为什么在PF 5.1版本之前它工作正常。

Bean代码

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);   

}

我现在只在bean和getter / setter方法中提供带有null值的filteredValue引用。现在它正常工作。

Bean代码

private List filteredResults = null;

   public List getFilteredResults() {
      return filteredResults;
   }

   public void setFilteredResults(List filteredResults) {
      this.filteredResults = filteredResults;
   }

答案 1 :(得分:0)

commandLink searchId内使用oncomplete代替onclick,然后再试一次。

您也可以从action更改为actionListener

要了解详情,请阅读this post