国际化中的解析异常-找不到消息 [英] Parsing Exception in Internationalization - message not being found

查看:137
本文介绍了国际化中的解析异常-找不到消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开始开发程序之前,我正在尝试使我的应用程序国际化,以便以后对它进行扩展更容易.

Im trying to internationalize my application before I get started in developing so its easier for me to expand it later.

尽管我尝试遵循这些教程,但我总是遇到相同的错误:我的xhtml中的标签无法解析,好像没有消息一样(即使Eclipse自动完成了它们也是如此).

However as much as I try to follow tutorials, I always get the same error: the tags in my xhtml fail to be parsed, as if the massage did not even exist (even though Eclipse auto-completes them).

堆栈跟踪的摘要如下(此处是Pastebin的完整堆栈跟踪):

The summary of the stacktrace is as follows (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/package organization:

Faces-Config.xml:

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

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

I'm using Java 8 + JSF2.2 + Tomcat 9

动态Web模块为3.1

The Dynamic Web Module is 3.1

推荐答案

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

I'm very confident that changing #{msg.['title.index']}" to #{msg['title.index']}" (removing the .) helps a lot

这篇关于国际化中的解析异常-找不到消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆