不推荐使用主线程上的同步xmlhttprequest导致意外行为

时间:2016-12-08 04:42:28

标签: jquery jsf primefaces jsf-2 datatable

我正在使用PrimeFaces 5.1,myfaces 2.0。以前使用PrimeFaces 3.5,它工作正常。我有p:dataTable和p:commandLink。我有一个服务器端方法来清除过滤器。当我点击p:dataTable中的p:commandLink时,它会转到另一个页面,但是控制台显示"未捕获的TypeError:无法读取属性' clearFilters'未定义"。它只发生在单击p:commandLink时。知道为什么吗?

XHTML

    sample.js
{...
$scope.temp=$scope.data[i].Src;
...
}
sample.html
{...
<img src={{temp}}>
...
}

请求bean

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

控制台错误

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";
}

1 个答案:

答案 0 :(得分: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";