2016-12-08 52 views
0

我正在使用PrimeFaces 5.1,myfaces 2.0。以前是使用PrimeFaces 3.5,它工作正常。我有p:dataLink和p:commandLink。我有一個服務器端方法來清除過濾器。當我點擊p:dataTable中的p:commandLink時,它會轉到另一個頁面,但控制檯顯示「Uncaught TypeError:無法讀取未定義的屬性'clearFilters'」。它只發生在點擊p:commandLink時。任何想法爲什麼?主線程上的同步xmlhttprequest被棄用導致意外的行爲

XHTML

<table border="0" cellpadding="0" cellspacing="0"> 
    <tbody> 
     <tr> 
      <td valign="top" width="620"><p:dataTable styleClass="dataTable" id="db1001_datatable_dashboards" 
        paginator="true" rows="50" 
        paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
        rowsPerPageTemplate="10,25,50,75,100,200" 
        resizableColumns="true" paginatorPosition="bottom" 
        value="#{pc_Db1001.w_dashboard.listOfDashboards}" 
        var="varlistOfDashboards" filteredValue="#{pc_Db1001.w_dashboard.listOfFilteredDashboards}" 
        widgetVar="listOfDashboards"> 

        <p:ajax event="filter" listener="#{pc_Db1001.filterListener}"></p:ajax> 

        <p:column id="db1001_column_selector" width="20"> 
         <p:selectBooleanCheckbox styleClass="selectBooleanCheckbox" 
          id="db1001_checkbox_checkbox" 
          value="#{varlistOfDashboards.selected}"></p:selectBooleanCheckbox> 
         <f:attribute value="top" name="valign" /> 
        </p:column> 

        <p:column id="db1001_column_chart_type" style="text-align: left;font-weight: 400" 
         width="100" sortBy="#{varlistOfDashboards.chart_type_dn}" 
         resizable="true" headerText="#{msg.db1001_gridheader_chart_type}" 
         filterBy="#{varlistOfDashboards.chart_type_dn}" 
         filterMatchMode="contains" 
         filterStyle="width: 90px;align: left;" 
         filterStyleClass="filterInputText" 
         filterValue="#{pc_Db1001.w_dashboard.fv_chart_type_dn}"> 
         <h:outputText styleClass="outputGridText" 
          id="db1001_gridoutput_chart_type_dn" 
          value="#{varlistOfDashboards.chart_type_dn}"></h:outputText> 
         <f:attribute value="true" name="nowrap" /> 
         <f:attribute value="top" name="valign" /> 
        </p:column> 

        <p:column id="db1001_column_category" style="text-align: left;font-weight: 400" 
         width="90" sortBy="#{varlistOfDashboards.category_dn}" 
         resizable="true" headerText="#{msg.db1001_gridheader_category}" 
         filterBy="#{varlistOfDashboards.category_dn}" 
         filterMatchMode="contains" 
         filterStyle="width: 80px;align: left;" 
         filterStyleClass="filterInputText" 
         filterValue="#{pc_Db1001.w_dashboard.fv_category_dn}"> 
         <h:outputText styleClass="outputGridText" 
          id="db1001_gridoutput_category" 
          value="#{varlistOfDashboards.category_dn}"></h:outputText> 
         <f:attribute value="true" name="nowrap" /> 
         <f:attribute value="top" name="valign" /> 
        </p:column> 

        <p:column id="db1001_column_shortname" style="text-align: left;font-weight: 400" 
         width="350" sortBy="#{varlistOfDashboards.shortname}" 
         resizable="true" 
         headerText="#{msg.db1001_gridheader_shortname}" 
         filterBy="#{varlistOfDashboards.shortname}" 
         filterMatchMode="contains" 
         filterStyle="width: 340px;align: left;" 
         filterStyleClass="filterInputText" 
         filterValue="#{pc_Db1001.w_dashboard.fv_shortname}"> 
         <p:commandLink ajax="false" styleClass="commandLink" 
          id="db1001_commandlink_shortname" 
          action="#{pc_Db1001.doDb1001_commandlink_shortnameAction}"> 
          <h:outputText id="db1001_gridoutput_shortname" 
           styleClass="outputGridText_80px" 
           value="#{varlistOfDashboards.shortname}"></h:outputText> 
          <f:param name="db1001_click_rptsysid" 
           value="#{varlistOfDashboards.rptsysid}"></f:param> 
         </p:commandLink> 
         <f:attribute value="true" name="nowrap" /> 
         <f:attribute value="top" name="valign" /> 
        </p:column> 

        <p:column id="db1001_column_maintain" width="60"> 
         <f:facet name="header"> 
         </f:facet> 
         <p:commandLink ajax="false" styleClass="commandLink" id="link1" 
          action="#{pc_Db1001.doDb1001_commandlink_configureAction}"> 
          <h:outputText id="db1001_commandlink_maintain" 
           styleClass="outputGridText_px" 
           value="#{msg.db1001_commandlink_configure}"></h:outputText> 
          <f:param name="db1001_click_rptsysid" 
           value="#{varlistOfDashboards.rptsysid}"></f:param> 
         </p:commandLink> 
         <f:attribute value="true" name="nowrap" /> 
         <f:attribute value="left" name="align" /> 
         <f:attribute value="top" name="valign" /> 
        </p:column> 

       </p:dataTable> 
      </td> 
     </tr> 
    </tbody> 
</table> 

請求Bean

private void setFiltersNull() { 
    String _LOC = "[Db1001: setFiltersNull]"; 

    W_dashboard _w = getW_dashboard(); 

    _w.setListOfFilteredDashboards(null); 
    _w.setFv_chart_type_dn(null); 
    _w.setFv_category_dn(null); 
    _w.setFv_shortname(null); 
} 

public void clearFilters() { 
    String _LOC = "[Db1001: clearFilters]"; 

    W_dashboard _w = getW_dashboard(); 

    try { 
     setFiltersNull(); 

     //get datatable 
     DataTable table = (DataTable) findComponentInRoot("db1001_datatable_dashboards"); 

     if (table != null) { 
      //clear sort 
      ValueExpression ve = table.getValueExpression("sortBy"); 
      if (ve != null) { 
       table.setValueExpression("sortBy", null); 
      } 

      //clear filtering 
      String _widgetVar = table.getWidgetVar(); 
      String jsFunctionStr = "PF('" + _widgetVar + "').clearFilters();"; 
      RequestContext context = RequestContext.getCurrentInstance(); 
      context.execute(jsFunctionStr); 

      //reset datatable 
      table.reset(); 
     } 
    }catch (Exception e) { 
    } 
} 

public void filterListener(FilterEvent filterEvent) { 
    String _LOC = "[Db1001: filterListener]"; 
//  System.out.println(_LOC + "1.0"); 

    W_dashboard _w = getW_dashboard(); 

    try { 
     //Get datatable 
     DataTable table = (DataTable)filterEvent.getSource(); 

     //Clear checkbox in main list 
     List _main_list = _w.getListOfDashboards(); 
     List _filtered_list = _w.getListOfFilteredDashboards(); 

     if (!isEmptyNull(_main_list)) { 
      for (Iterator iter = _main_list.iterator(); iter.hasNext();) { 
       W_dashboard _wm = (W_dashboard) iter.next(); 

       _wm.setSelected(false); 
      } 
     } 

     //Clear checkbox in filtered list 
     if (!isEmptyNull(_filtered_list)) { 
      for (Iterator iter = _filtered_list.iterator(); iter.hasNext();) { 
       W_dashboard _wm = (W_dashboard) iter.next(); 

       _wm.setSelected(false); 
      } 
     } 

     //Retain filters by setting to managed bean 
     //From listing page, click new, cancel out to listing page, the filter is not "remembered" 
     Map filters = table.getFilters(); 
     System.out.println("1.0 " + " filters:" + filters); 

     if(filters != null) { 

      //dashboardid 
      String _filterText = (String)filters.get("chart_type_dn"); 
      if(!isEmptyNull(_filterText)) { 
       _w.setFv_chart_type_dn(_filterText); 
      }else { 
       _w.setFv_chart_type_dn(null); 
      } 

      //category 
      _filterText = (String)filters.get("category_dn"); 
      if(!isEmptyNull(_filterText)) { 
       _w.setFv_category_dn(_filterText); 
      }else { 
       _w.setFv_category_dn(null); 
      } 

      //description 
      _filterText = (String)filters.get("shortname"); 
      if(!isEmptyNull(_filterText)) { 
       _w.setFv_shortname(_filterText); 
      }else { 
       _w.setFv_shortname(null); 
      } 
     } 
    }catch (Exception e) { 
    } 
} 

public String doDb1001_commandlink_shortnameAction() { 
    String _LOC = "[Db1001: doDb1001_commandlink_shortnameAction]"; 
//  System.out.println(_LOC + "1.0"); 

    Map _rp = getRequestParam(); 
    String _rptsysid = (String) _rp.get("db1001_click_rptsysid"); 
    W_dashboard _w = getW_dashboard(); 

    if (_rptsysid != null) { 
     Integer _rightid = _w.getDashboardRightsid(_rptsysid); 
     if (_rightid == null) { 
      showCommonMessage_ByKey("db1001_message_delete_noaccessright_setup"); 
      return null; 
     } else { 
      if (cannotAccess(_rightid.intValue())) { 
       showCommonMessage_ByKey_With3Parameter("db1001_message_delete_noaccessright" 
         , _rightid, null, null); 
       return null; 
      } 
     } 
    } 

    //clear sorting and filtering 
    clearFilters(); 

    return "db1001_commandlink_shortname_success"; 
} 

在控制檯上的錯誤

Uncaught TypeError: Cannot read property 'clearFilters' of undefined(…) 
    (anonymous function) @ db1001.xhtml:534 
    i @ jquery.js?ln=primefaces&v=5.1:25 
    fireWith @ jquery.js?ln=primefaces&v=5.1:25 
    ready @ jquery.js?ln=primefaces&v=5.1:25 
    bZ @ jquery.js?ln=primefaces&v=5.1:25 
+0

嘗試打印出來jsFunctionStr,並在控制檯 –

+0

@ JaqenH'ghar運行它如何運行,在控制檯?在非ajax commandLink中調用clearFilters()是否重要? – bittersour

+0

@ JaqenH'ghar我試圖在控制檯中運行它。同樣的錯誤。 – bittersour

回答

0

相反的:

String _widgetVar = table.getWidgetVar(); 
String jsFunctionStr = "PF('" + _widgetVar + "').clearFilters();"; 

更改爲:

String _tableid = table.getId(); 
String jsFunctionStr = "$('#" + _tableid + "').find('thead > tr > th.ui-filter-column > .ui-column-filter').val('');" + "$(this.jqId+'\\\\:globalFilter').val('');" + "this.filter"; 
相關問題