fmt:带有properties.get的消息未返回正确的消息

时间:2017-01-03 17:34:30

标签: jsp aem

在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时遇到问题,可以&lt; a href =&#34; https://get.adobe.com/uk/reader/otherversions/"&gt;下载Adobe Reader&lt; /一个&GT;来自Adobe免费。

1 个答案:

答案 0 :(得分:0)

试试此代码

 <%@ 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>