p:commandLink 切换到 Primefaces 7.0 后不再调用 actionListener

p:commandLink actionListener not invoked anymore after switching to Primefaces 7.0

我最近更新了我的项目库。 Primefaces 5.2 > 7.0 我的脸 2.1.13 > 2.2.12

更新后 <p:commandLink>s actionListener 之一不再被调用。 我在 oncomplete 中的 javascript 代码工作正常,一个 ajax 请求被发送到服务器并且 returns 一个很好的响应,但是没有调用 actionListener。

commandLink 在 p:dataTable.

并且检查员控制台没有报错!

我遵循了这个答案: 但运气不好。

豆子:

public class TestBean {

    public static final Logger log = Logger.getLogger(TestBean.class);


    private List<TestDataDto> testData;
    private SubDataDto selectedData;
    private String title;


    public List<TestDataDto> getTestData() {
        return testData;
    }

    public SubDataDto getSelectedData() {
        return selectedData;
    }

    public String getTitle() {
        return title;
    }

    public void loadTestData() {
        this.testData = new ArrayList<>();
        TestDataDto e = new TestDataDto();
        ArrayList<SubDataDto> subDatas = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            SubDataDto dto = new SubDataDto();
            dto.setRowNumber(i + 1);
            dto.setTitle("title " + i + " item");
            dto.setType((i % 2 == 0) ? "Even" : "Odd");
            dto.setAmount((i + 1) * 10000);
            subDatas.add(dto);
        }
        e.setSubDatas(subDatas);
        testData.add(e);
    }

    public void setSelectedDataTitle(String title) {
        this.title = title;
    }

}

流量:

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/webflow
      http://www.springframework.org/schema/webflow/spring-webflow.xsd">


    <view-state id="test">
        <on-entry>
            <evaluate expression="testBean.loadTestData()"/>
        </on-entry>
    </view-state>


</flow>

xhtml :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:sec="http://www.springframework.org/security/sabatags">
<f:view locale="#{themeSwitcherBean.localeCode}">


    <h:head>
        <title>#{msgs['application.title']}  : <ui:insert name="title">#{msgs['empty.page.header']}</ui:insert></title>
        <meta http-equiv="Pragma" content="no-store"/>
        <meta http-equiv="Cache-Control" content="no-store"/>
        <meta http-equiv="Expires" content="-1"/>
        <meta name="viewport" content="width=device-width, initial-scale=1"/>

        <ui:insert name="styles"/>
        <ui:insert name="inHead"/>

        <h:outputScript name="js/number.js" target="head"/>

        <h:outputScript name="js/amountConvertor.js" target="head"/>

        <link type="text/css" rel="stylesheet" media="all"
              href="#{request.contextPath}/resources/css/bootstrap.min.css"/>
        <link type="text/css" rel="stylesheet" media="all"
              href="#{request.contextPath}/resources/css/style.css"/>
        <link type="text/css" rel="stylesheet" media="all"
              href="#{request.contextPath}/resources/css/font-awesome.min.css"/>
        <link type="text/css" rel="stylesheet"
              href="#{request.contextPath}/resources/css/custom-primefaces.css"/>
        <link type="text/css" rel="styl esheet"
              href="#{request.contextPath}#{themeSwitcherBean.directionStyleSheet}"/>
        <link type="text/css" rel="stylesheet"
              href="#{request.contextPath}/resources/css/countdown/jquery.countdown.css"/>
        <!--<link type="text/css" rel="stylesheet"-->
        <!--href="#{request.contextPath}/resources/css/morris.css"/>-->
        <script type="text/javascript"
                src="#{request.contextPath}/resources/js/saba-primefaces-ext.js"></script>
        <script type="text/javascript"
                src="#{request.contextPath}/resources/js/countdown/jquery.plugin.min.js"></script>
        <script type="text/javascript"
                src="#{request.contextPath}/resources/js/countdown/jquery.countdown.min.js"></script>
        <link type="text/css" rel="stylesheet"
              href="#{request.contextPath}/resources/css/sib-reportviewer.css"/>
        <script type="text/javascript"
                src="#{request.contextPath}/resources/js/sib-reportviewer.js"></script>
        <h:outputScript library="js" name="jquery.ui.datepicker.js"
                        rendered="#{themeSwitcherBean.localeCode == 'FA' or themeSwitcherBean.localeCode == 'fa'}"/>
        <h:outputScript library="js" name="jquery.ui.datepicker-cc.all.min.js"
                        rendered="#{themeSwitcherBean.localeCode == 'FA' or themeSwitcherBean.localeCode == 'fa'}"/>
        <h:outputScript library="js" name="jquery.ui.datepicker-fa.js"
                        rendered="#{themeSwitcherBean.localeCode == 'FA' or themeSwitcherBean.localeCode == 'fa'}"/>

        <h:outputScript library="js" name="raphael-min.js"/>
        <h:outputScript library="js" name="morris-0.4.1.min.js"/>
        <h:outputScript library="js" name="moment.js"/>
        <h:outputScript library="js" name="moment-jalaali.js"/>
    </h:head>


    <p:panel id="accountOverviewPanel" styleClass="tab-content">
        <h:form id="form">
        <h:inputHidden value="#{tabCheckBean.tabId}" id="form_client_id" readonly="true">
            <f:param name="name" value="_client_id"/>
        </h:inputHidden>
        <p:dataTable reflow="false" id="dataTable" var="data"
                     styleClass="table-bordered table-striped table-condensed cf"
                     value="#{testBean.testData}"
                     selection="#{testBean.selectedData}"
                     selectionMode="single"
                     currentPageReportTemplate="#{msgs['primefaces.currentPageReportTemplate']}"
                     emptyMessage="#{msgs['primefaces.datagrid.no.data']}"
                     paginator="true"
                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                     rowsPerPageTemplate="5,10,15" lazy="true"
                     rows="10"
                     rowIndexVar="rowNum">

            <p:columnGroup type="header">
                <p:row>
                    <p:column headerText="RowNum"/>
                    <p:column headerText="Title"/>
                    <p:column headerText="Type"/>
                    <p:column headerText="Amount"/>
                    <p:column headerText="Actions"/>
                </p:row>
            </p:columnGroup>

            <p:subTable id="subData" var="sub" value="#{data.subDatas}">
                <p:column>
                    <h:outputText value="#{sub.rowNumber}"/>
                </p:column>

                <p:column>
                    <h:outputText value="#{sub.title}"/>
                </p:column>
                <p:column>
                    <h:outputText value="#{sub.type}"/>
                </p:column>
                <p:column>
                    <h:outputText value="#{sub.amount}"/>
                </p:column>

                <p:column>
                    <p:commandLink title="Show Data"
                                   actionListener="#{testBean.setSelectedDataTitle(sub.title)}"
                                   oncomplete="PF('subTitleDlg').show()"
                                   update=":subTitleDialog" ajax="true">
                        <p:graphicImage value="/resources/img/save.png"/>
                    </p:commandLink>
                </p:column>
            </p:subTable>
        </p:dataTable>
        </h:form>

    </p:panel>

    <p:dialog id="subTitleDialog" widgetVar="subTitleDlg" dynamic="true"
              modal="true" closable="true" closeOnEscape="true"
              width="450" visible="false">
        <br/>
        <p:outputLabel value="selected title is : "/>

        <div style="text-align: left;">
            <p:outputLabel value="#{testBean.title}"/>
        </div>
    </p:dialog>

</f:view>
</html>

当我点击保存命令链接时,我希望执行 actionListener,然后打开对话框并显示所选标题。

我在目标方法中添加了一个断点,但那里没有任何反应。

知道如何找到问题并解决它吗?

显然数据表中的 commandLink 有问题。 尝试 h:commandLink 也没有解决问题。

所以我必须做一个小技巧才能让它再次工作。

我在我的表单中的数据表外添加了一个隐藏输入,然后在我的 commandLink 的单击事件上更新了它的值,并设置 commandLink 来处理它。 更改如下所示:

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
>
<f:view>


    <h:head>
        <title>#{msgs['application.title']}  : <ui:insert name="title">#{msgs['empty.page.header']}</ui:insert></title>
        <meta http-equiv="Pragma" content="no-store"/>
        <meta http-equiv="Cache-Control" content="no-store"/>
        <meta http-equiv="Expires" content="-1"/>
        <meta name="viewport" content="width=device-width, initial-scale=1"/>

        <ui:insert name="styles"/>
        <ui:insert name="inHead"/>

        <h:outputScript name="js/number.js" target="head"/>
        <!--<h:outputScript name="js/jquery-3.2.1.min.js" target="head"/>-->
        <h:outputScript name="js/amountConvertor.js" target="head"/>
        <!--<h:outputScript name="js/bootstrap.min.js" target="head"/>-->
        <!--<h:outputScript name="js/custome.js" target="head"/>-->
        <!--<script type="text/javascript"-->
        <!--src="#{themeSwitcherBean.applicationPath}/resources/js/custome.js"></script>-->


        <link type="text/css" rel="stylesheet" media="all"
              href="#{themeSwitcherBean.applicationPath}/resources/css/bootstrap.min.css"/>
        <link type="text/css" rel="stylesheet" media="all"
              href="#{themeSwitcherBean.applicationPath}/resources/css/style.css"/>
        <link type="text/css" rel="stylesheet" media="all"
              href="#{themeSwitcherBean.applicationPath}/resources/css/font-awesome.min.css"/>
        <link type="text/css" rel="stylesheet"
              href="#{themeSwitcherBean.applicationPath}/resources/css/custom-primefaces.css"/>
        <link type="text/css" rel="stylesheet"
              href="#{themeSwitcherBean.applicationPath}#{themeSwitcherBean.directionStyleSheet}"/>
        <link type="text/css" rel="stylesheet"
              href="#{themeSwitcherBean.applicationPath}/resources/css/countdown/jquery.countdown.css"/>
        <!--<link type="text/css" rel="stylesheet"-->
        <!--href="#{themeSwitcherBean.applicationPath}/resources/css/morris.css"/>-->
        <script type="text/javascript"
                src="#{themeSwitcherBean.applicationPath}/resources/js/saba-primefaces-ext.js"></script>
        <script type="text/javascript"
                src="#{themeSwitcherBean.applicationPath}/resources/js/countdown/jquery.plugin.min.js"></script>
        <script type="text/javascript"
                src="#{themeSwitcherBean.applicationPath}/resources/js/countdown/jquery.countdown.min.js"></script>
        <link type="text/css" rel="stylesheet"
              href="#{themeSwitcherBean.applicationPath}/resources/css/sib-reportviewer.css"/>
        <script type="text/javascript"
                src="#{themeSwitcherBean.applicationPath}/resources/js/sib-reportviewer.js"></script>
        <h:outputScript library="js" name="jquery.ui.datepicker.js"
                        rendered="#{themeSwitcherBean.localeCode == 'FA' or themeSwitcherBean.localeCode == 'fa'}"/>
        <h:outputScript library="js" name="jquery.ui.datepicker-cc.all.min.js"
                        rendered="#{themeSwitcherBean.localeCode == 'FA' or themeSwitcherBean.localeCode == 'fa'}"/>
        <h:outputScript library="js" name="jquery.ui.datepicker-fa.js"
                        rendered="#{themeSwitcherBean.localeCode == 'FA' or themeSwitcherBean.localeCode == 'fa'}"/>

        <h:outputScript library="js" name="raphael-min.js"/>
        <h:outputScript library="js" name="morris-0.4.1.min.js"/>
        <h:outputScript library="js" name="moment.js"/>
        <h:outputScript library="js" name="moment-jalaali.js"/>
    </h:head>


    <p:panel id="accountOverviewPanel" styleClass="tab-content">
        <h:form id="form">
            <h:inputHidden value="#{tabCheckBean.tabId}" id="form_client_id" readonly="true">
                <f:param name="name" value="_client_id"/>
            </h:inputHidden>
            <p:inputText type="hidden" widgetVar="selectedDataTitleWgt" id="selectedDataTitle"/>
            <p:dataTable reflow="false" id="dataTable" var="data"
                         styleClass="table-bordered table-striped table-condensed cf"
                         value="#{testBean.testData}"
                         selection="#{testBean.selectedData}"
                         selectionMode="single"
                         currentPageReportTemplate="#{msgs['primefaces.currentPageReportTemplate']}"
                         emptyMessage="#{msgs['primefaces.datagrid.no.data']}"
                         paginator="true"
                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                         rowsPerPageTemplate="5,10,15" lazy="true"
                         rows="10"
                         rowIndexVar="rowNum">

                <p:columnGroup type="header">
                    <p:row>
                        <p:column headerText="RowNum"/>
                        <p:column headerText="Title"/>
                        <p:column headerText="Type"/>
                        <p:column headerText="Amount"/>
                        <p:column headerText="Actions"/>
                    </p:row>
                </p:columnGroup>

                <p:subTable id="subData" var="sub" value="#{data.subDatas}">
                    <p:column>
                        <h:outputText value="#{sub.rowNumber}"/>
                    </p:column>

                    <p:column>
                        <h:outputText value="#{sub.title}"/>
                    </p:column>
                    <p:column>
                        <h:outputText value="#{sub.type}"/>
                    </p:column>
                    <p:column>
                        <h:outputText value="#{sub.amount}"/>
                    </p:column>

                    <p:column>
                        <p:commandLink title="Show Data"
                                       onclick="PF('selectedDataTitleWgt').jq.val('#{sub.title}');"
                                       process=":form:selectedDataTitle"
                                       ajax="true">
                            <p:graphicImage value="/resources/images/save.png"/>
                        </p:commandLink>
                    </p:column>
                </p:subTable>
            </p:dataTable>
        </h:form>

    </p:panel>


</f:view>
</html>