【问题标题】:view id is null after changing the language更改语言后视图 ID 为空
【发布时间】:2013-02-08 12:25:56
【问题描述】:

我正在使用 PrimeFaces 3.4.1、MyFaces 2.0.7、Websphere Application Server 7。

我正在使用带有 3 个标签的 p:tabView 组件。当我在 first tab 中更改语言时,应用程序工作正常,没有任何错误。但是如果我去 second or third tab -> 更改语言 -> 然后导航到任何一个非活动选项卡。我得到以下异常。

 Caused by: java.io.FileNotFoundException: Facelet /.xhtml?REQUIRED=false not found at: file:/opt/IBM/WebSphere/AppServer/profiles/mblade140/installedApps/mblade140/ldapmanager-application-ear.ear/ldapmanager-application-web.war/.xhtml?REQUIRED=false
[08.02.13 12:55:42:349 CET] 00000090 SystemErr     R    at org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory._createFacelet(DefaultFaceletFactory.java:286)

以下是我为 p:tabView 组件编写代码的方式

    <h:form id="headerForm" prependId="false">
    <h:inputHidden id="activeTabIndexId" value="#{AppUserManagementBean.activeTabIndex}" />
    <p:remoteCommand update="tabView:fieldAppUserMgmt,tabView:filterApps,tabView:filterRoles,tabView:panel_grid_newuser" 
            name="onTabChange" 
            process="activeTabIndexId,@this" 
            actionListener="#{AppUserManagementBean.onTabChanged}" >
            <f:param name="REQUIRED" value="false"/>
    </p:remoteCommand>

    <p:tabView id="tabView" dynamic="true" cache="true" activeIndex="#{AppUserManagementBean.activeTabIndex}"
        onTabChange="document.getElementById('activeTabIndexId').value = index;onTabChange();">

        <p:tab id="userManagementTab" title="#{msgs.UserManagement_Title}">
            <ui:include src="UserManagement.xhtml" />
        </p:tab>
        <p:tab id="applicationUserManagementTab"
            title="#{msgs.AppUserMgmt_Title}">
            <ui:include src="AppUserManagement.xhtml" />
        </p:tab>
        <p:tab id="userGroupManagementTab"
            title="#{msgs.UserGroupMgmt_Title}">
            <ui:include src="UserGroupManagement.xhtml" />
        </p:tab>
    </p:tabView>
</h:form>

这是我为更改支持 bean 中的语言而编写的代码。在 p:selectOneMenu

中更改语言时调用此方法
    public void setLocale(String selectedLocale) {
    System.out.println("Changing locale to "+selectedLocale);
    this.locale = selectedLocale;
    for (Map.Entry<String, Locale> entry : countryMap.entrySet()) {
        if (entry.getValue().toString().equals(selectedLocale)) {
            FacesContext.getCurrentInstance().getViewRoot()
                    .setLocale((Locale) entry.getValue());
        }
    }
}

我在这里做错了什么?有人能解释一下吗?

【问题讨论】:

  • onTabChange 中的所有内容,您为什么不使用 &lt;p:ajax/&gt;
  • 那是 b'coz,在第一个选项卡中,我放置了 4 个 raido 按钮,并使用部分渲染加载了 xhtml 页面。当我从第一个选项卡移出第二个或第三个选项卡并尝试在第二个或第三个选项卡中提交表单时,JSF 也会处理第一个选项卡中的 ajax 请求。在理想情况下,JSF 不应该验证第一个选项卡中的字段,因为它不处于活动状态。 JSF 验证在第一个选项卡中的输入字段上触发,因此 JSF 不允许在第二个或第三个选项卡中提交表单,因为第一个选项卡中的验证失败。要解决此问题,我必须使用此解决方法。

标签: jsf-2 primefaces


【解决方案1】:

搞定了……

问题是我为 p:tabView 设置了 dynamic=true。我已删除 dynamic=true。语言更改选项现在正在工作。不知道为什么……

【讨论】:

    猜你喜欢
    • 2012-04-04
    • 2018-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-12
    • 1970-01-01
    相关资源
    最近更新 更多