0

我们在带有 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 时比它不起作用。

我们如何解决这个问题?

4

1 回答 1

0
<spring:message code="msg.x.x.x"  />

在使用 FastPageParser 的装饰器上对我来说效果很好。

有几件事要检查..

  • 您是否在装饰器中包含 springframework 和 sitemesh 标签库?

  • 我不确定它是否会对过滤器链产生影响,但我正在使用自定义配置装饰器映射器,它根据请求范围中设置的布局选择装饰器。

所以在 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 代替?

于 2012-02-02T17:32:21.437 回答