【问题标题】:PrimeFaces confirmDialog won't show after changing languagePrimeFaces confirmDialog 更改语言后不会显示
【发布时间】:2020-06-18 05:49:31
【问题描述】:

我有一个表格,里面有一个数据表。其中一列是删除该行的按钮。该按钮附有一个 primefaces 确认对话框。

<h:form id="form" style="text-align: -webkit-center">
            <p:dataTable id="preferenceConfigs" var="preferenceConfig"
                         value="#{preferenceManagementBackingBean.preferenceConfigs}">
                <p:column style="width:6rem; text-align: center">
                    <p:commandButton update=":form"
                                     title="#{msgs['common.delete.userpreference.button']}"
                                     icon="fa fa-trash"
                                     action="#{preferenceManagementBackingBean.invalidatePreferenceConfig(preferenceConfig)}">
                        <p:confirm header="Confirmation" message="#{msgs['common.dialog.preference.config.warning']}"
                                   icon="fa fa-exclamation-circle" escape="false"/>
                    </p:commandButton>
            </p:dataTable>

            <p:confirmDialog global="true" showEffect="fade" hideEffect="fade" style="text-align-last: center">
                <p:commandButton value="#{msgs['common.dialog.confirm.yes']}" type="button"
                                 styleClass="ui-confirmdialog-yes" icon="fa fa-check"/>
                <p:commandButton value="#{msgs['common.dialog.confirm.no']}" type="button"
                                 styleClass="ui-confirmdialog-no" icon="fa fa-times"/>
            </p:confirmDialog>
        </h:form>

在我通过 commandLink 更改页面上的语言之前,一切正常。它们位于此文件上方的 masterLayout 文件中:

<h:form id="generalSettingsForm">
                            <ul id="language">
                                <li><h:commandLink
                                        action="#{languageSessionBean.changeLanguage('en')}" value="EN"
                                        class="blgm_lSwitch" id="EN"/></li>
                                <li><h:commandLink
                                        action="#{languageSessionBean.changeLanguage('nl')}" value="NL"
                                        class="blgm_lSwitch" id="NL"/></li>
                                <li><h:commandLink
                                        action="#{languageSessionBean.changeLanguage('fr')}" value="FR"
                                        class="blgm_lSwitch" id="FR"/></li>
                            </ul>
                        </h:form>
    public void changeLanguage(String language) {
        locale = new Locale(language);
        findCurrentFacesContext().getViewRoot().setLocale(locale);
    }

这会刷新页面并显示正确的语言。但是,现在按下删除按钮会自动执行操作,而没有任何确认对话框的迹象。只有当我打开另一个对话框(存在于 JSF 页面中)并返回时,确认才会再次显示它的面孔...

开发控制台给了我以下错误:

VM1391 components.js.xhtml:13 Uncaught TypeError: Cannot read property 'style' of undefined
    at c.show (VM1391 components.js.xhtml:13)
    at c.showMessage (VM1391 components.js.xhtml:13)
    at Object.confirm (VM1391 components.js.xhtml:1)
    at Object.confirm (VM1390 core.js.xhtml:1)
    at HTMLButtonElement.onclick (preferenceManagement.xhtml:58)

有什么见解吗?

【问题讨论】:

  • 你在哪里有那个commandLink?
  • 我已编辑问题以包含 commandlinke。它位于“主”JSF 页面中
  • 我在下面找到了“解决方案”。它还有一个复制器。

标签: primefaces jsf-2


【解决方案1】:

似乎confirmDialog 不能很好地配合ajax 更新。

通常语言更改意味着必须更新页面的所有部分,因此使用部分更新没有任何好处。

解决这个问题的简单方法是在你的 commandLinks 上将 ajax 设置为 false:

<h:commandLink action="#{languageSessionBean.changeLanguage('fr')}" 
               value="FR" class="blgm_lSwitch" id="FR" ajax="false" />

【讨论】:

  • 不幸的是它并没有改变行为
【解决方案2】:

经过一番谷歌搜索后,primefaces 6.2 似乎存在以下问题:

confirmDialog 不显示,控制台上记录了一个错误(TypeError: this.jqEl 未定义)

这已在 6.2.2 中修复。我自己无法对此进行测试,因为所有次要版本都仅供付费用户使用。作为一种解决方法,我将尝试自定义对话框。您可能还可以使用 primefaces 7.0

official github with reproducer

【讨论】:

    【解决方案3】:

    您可以尝试将p:confirmDialog 从表格中删除吗?像这样的:

    <p:confirmDialog global="true" showEffect="fade" hideEffect="fade" style="text-align-last: center">
        <p:commandButton value="#{msgs['common.dialog.confirm.yes']}" type="button"
                         styleClass="ui-confirmdialog-yes" icon="fa fa-check"/>
        <p:commandButton value="#{msgs['common.dialog.confirm.no']}" type="button"
                         styleClass="ui-confirmdialog-no" icon="fa fa-times"/>
    </p:confirmDialog>
    
    <h:form id="form" style="text-align: -webkit-center">
        <p:dataTable id="preferenceConfigs" var="preferenceConfig"
            value="#{preferenceManagementBackingBean.preferenceConfigs}">
            <p:column style="width:6rem; text-align: center">
                <p:commandButton update=":form" icon="fa fa-trash"
                    title="#{msgs['common.delete.userpreference.button']}"
                    action="#{preferenceManagementBackingBean.invalidatePreferenceConfig(preferenceConfig)}">
                    <p:confirm header="Confirmation" message="#{msgs['common.dialog.preference.config.warning']}"
                               icon="fa fa-exclamation-circle" escape="false"/>
            </p:commandButton>
        </p:dataTable>
    </h:form>
    

    【讨论】:

    • 问题依旧
    • 你能试试这个吗?
    • 不要改变答案。如果您想提出新答案,请创建一个新答案。
    【解决方案4】:

    使用primefaces 6.2版本发生了同样的事情,然后努力搜索我发现这个解决方案完美运行,我希望它可以帮助某人,在web xml中添加:

    <context-param>
       <param-name>primefaces.MOVE_SCRIPTS_TO_BOTTOM</param-name>
       <param-value>true</param-value>
    </context-param>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-05
      • 2014-08-10
      • 2021-03-01
      • 2013-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多