我们在Sitemesh 2的项目中使用spring:message标记。 在装饰器中使用spring:message时,无法识别-tag。我们可以在jsp页面中使用-tag但在装饰器jsp文件中使用。
<?xml version="1.0" encoding="UTF-8"?>
<excludes/>
<page-parsers>
<parser content-type="text/html" encoding="UTF-8" class="com.opensymphony.module.sitemesh.parser.FastPageParser" />
</page-parsers>
<decorator-mappers>
<mapper class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
<param name="config" value="${decorators-file}" />
</mapper>
</decorator-mappers>
如果我们使用弃用的解析器FastPageParser比没有问题,但是当使用新的HTMLPageParser时却不起作用。
我们如何解决这个问题?
答案 0 :(得分:0)
<spring:message code="msg.x.x.x" />
使用FastPageParser在装饰器上正常工作。
要检查的一些事情......
您是否在装饰器上包含了springframework和sitemesh标签库?
我不确定它是否会对过滤器链产生影响,但我使用的是自定义configdecorator映射器,它根据请求范围中设置的布局选择装饰器。
< / LI>所以在sitemesh.xml中:
<decorator-mappers>
<mapper class="org.x.x.CustomConfigDecoratorMapper">
<param name="config" value="${decorators-file}" />
</mapper>
</decorator-mappers>
CustomConfigDecoratorMapper看起来像这样:
public class CustomConfigDecoratorMapper extends AbstractDecoratorMapper {
private static final Logger logger = Logger.getLogger(CustomConfigDecoratorMapper.class);
private ConfigLoader configLoader = null;
public void init(Config config, Properties properties, DecoratorMapper parent) throws InstantiationException
{
super.init(config, properties, parent);
try
{
String fileName = properties.getProperty("config", "/WEB-INF/decorators.xml");
configLoader = new ConfigLoader(fileName, config);
}
catch (Exception e)
{
throw new InstantiationException(e.toString());
}
}
public Decorator getDecorator(HttpServletRequest request, Page page)
{
String layoutName = "default";
String configLayoutName = ( String)request.getParameter("layoutName" );
if ( configLayoutName == null )
{
configLayoutName = (String)request.getAttribute("layoutName");
if ( configLayoutName == null )
{
configLayoutName = "default";
}
}
if ( configLayoutName != null )
{
layoutName = configLayoutName;
}
Decorator result = getNamedDecorator(request, layoutName);
return result == null ? super.getDecorator(request, page) : result;
}
public Decorator getNamedDecorator(HttpServletRequest request, String name)
{
Decorator result = null;
try
{
result = configLoader.getDecoratorByName(name);
}
catch (ServletException e)
{
logger.error("getNamedDecorator(HttpServletRequest, String)", e);
}
if (result == null || (result.getRole() != null && !request.isUserInRole(result.getRole())))
{
return super.getNamedDecorator(request, name);
}
else
{
return result;
}
}
}
除此之外..你考虑过使用fmt:message吗?