【问题标题】:fmt:message with properties.get not returning proper messagefmt:message with properties.get 没有返回正确的消息
【发布时间】:2017-01-03 17:34:30
【问题描述】:

在 AEM 6.2 中,我试图获取带有嵌入 html 代码的 i18n 消息,以便在页面上正确处理。有一个标记为“i18nLabel”的花岗岩节点。当我以下列方式使用 fmt:message 时:

<fmt:message key="${properties.i18nLabel}"/>

它打印 ???I18NMESSAGE01???在页面上。

发生了什么事?它不应该将 I18NMESSAGE01 键格式化为它的文本值吗?

我尝试使用以下代码结构,它可以在页面上打印正确的消息,但它也打印 html 标签,而不是像写作那样正确处理它们。

<%@ page import="com.day.cq.i18n.I18n" %>
<% I18n i18n = new I18n(slingRequest); %>
<%
String i18nKey = properties.get("gl_label_i18nLabel", String.class);
String i18nMessage = i18n.get(i18nKey);
%><p><%= i18nMessage %></p><%
%>

i18n 消息是:

如果您在查看 PDF 时遇到问题,可以从 Adob​​e 免费下载 Adob​​e Reader

【问题讨论】:

    标签: jsp aem


    【解决方案1】:

    试试这个代码

     <%@ page import="java.util.*,com.day.cq.i18n.I18n" %>
    <c:set var="htmlMessage" value="${property:singleValue(resource,'i18nMessage', '')}"/>
    <c:if test="${empty htmlMessage}">
    <c:set var="htmlMessage"><fmt:message key="properties.i18nLabel"/></c:set>
    </c:if>
    

    【讨论】:

    • 如果我尝试在我的代码中使用它: 我得到以下错误: 引起:org.apache.sling.scripting.jsp.jasper.JasperException: /apps/dash/components/global/glb-label/glb-label.jsp(45,26) 属性前缀属性确实不对应任何导入的标签库
    猜你喜欢
    • 2018-11-06
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    • 1970-01-01
    • 2013-11-19
    • 2014-11-26
    相关资源
    最近更新 更多