解析国际化中的异常 - 未找到消息

时间:2018-05-17 15:06:21

标签: jsf internationalization el

我在开始开发之前试图将我的应用程序国际化,以便我以后更容易扩展它。

然而,尽管我尝试按照教程进行操作,但我总是得到同样的错误:我的xhtml中的标签无法解析,就好像按摩甚至不存在一样(即使Eclipse自动完成它们)。

stacktrace的摘要如下(Here for the full stacktrace at Pastebin):

Type Exception Report

Message /index.xhtml @11,50 value="#{msg.['title.index']}" Failed to parse the expression [#{msg.['title.index']}]

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

javax.servlet.ServletException: /index.xhtml @11,50 value="#{msg.['title.index']}" Failed to parse the expression [#{msg.['title.index']}]
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause

javax.faces.view.facelets.TagAttributeException: /index.xhtml @11,50 value="#{msg.['title.index']}" Failed to parse the expression [#{msg.['title.index']}]
    com.sun.faces.facelets.tag.TagAttributeImpl.getValueExpression(TagAttributeImpl.java:428)
    com.sun.faces.facelets.tag.TagAttributeImpl.getValueExpression(TagAttributeImpl.java:378)
    com.sun.faces.facelets.tag.jsf.ValueHolderRule$DynamicValueExpressionMetadata.applyMetadata(ValueHolderRule.java:129)
    com.sun.faces.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:81)
    javax.faces.view.facelets.MetaTagHandler.setAttributes(MetaTagHandler.java:129)
    javax.faces.view.facelets.DelegatingMetaTagHandler.setAttributes(DelegatingMetaTagHandler.java:102)
    com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.doNewComponentActions(ComponentTagHandlerDelegateImpl.java:491)
    com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:178)
    javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
    com.sun.faces.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:106)
    com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:206)
    com.sun.faces.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:395)
    com.sun.faces.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:366)
    com.sun.faces.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:111)
    javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
    javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
    com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:202)
    javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
    javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95)
    com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
    com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
    com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:312)
    com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:371)
    com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:350)
    com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:199)
    com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:174)
    com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
    com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87)
    com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:161)
    com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:991)
    com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:99)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

文件夹/包裹组织: Folder Organization

faces-config.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
    version="2.2">
    <application>
<!--        <message-bundle>messages_en_US</message-bundle> -->
<!--        <message-bundle>messages_es</message-bundle> -->
<!--        <message-bundle>messages_pt_BR</message-bundle> -->
        <locale-config>
            <default-locale>en_US</default-locale>
            <supported-locale>pt_BR</supported-locale>
            <supported-locale>es</supported-locale>
        </locale-config>

        <resource-bundle>
            <base-name>com.tfduque.fieldassist.interface</base-name>
            <var>msg</var>

        </resource-bundle>
    </application>

</faces-config>

的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">
    <display-name>FieldAssist</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

的index.xhtml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="WEB-INF/template/template.xhtml">


    <ui:define name="title">
        <h:outputText value="#{msg.['title.index']}" />

    </ui:define>
    <ui:define name="body">Welcome!</ui:define>

</ui:composition>
</html>

为此,模板:

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

<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title><ui:insert name="title">
            <h:message />
        </ui:insert></title>
    <!--    <h:outputStylesheet library="css" name="sistema.css" /> -->
    <!--    <h:outputStylesheet library="css" name="bootstrap.min.css" /> -->
</h:head>

<h:body>

    <div id="header">

        <header> </header>
    </div>
    <div id="body">
        <ui:insert name="body" />

    </div>



    <footer>
    <hr style="margin-top: 20px" />

    </footer>

</h:body>

</h>

我正在使用Java 8 + JSF2.2 + Tomcat 9

动态网络模块是3.1

1 个答案:

答案 0 :(得分:0)

我非常有信心将#{msg.['title.index']}"更改为#{msg['title.index']}"(删除。)会有很大帮助