Sitemesh spring:模板中无法识别消息

发布于 2025-01-01 05:50:03 字数 751 浏览 3 评论 0原文

我们在 Sitemesh 2 的项目中使用 spring:message 标签。 当在装饰器中使用 spring:message 时,无法识别 -tag 。我们可以在 jsp 页面中但在装饰器 jsp 文件中使用 -tag。

<?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 时则不起作用。

我们该如何解决这个问题呢?

We are using the spring:message tag in a project with Sitemesh 2.
When using the spring:message in the decorator than the -tag isn't recognized. We can use the -tag in our jsp pages but in the decorator jsp file.

<?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>

If we use the deprecated parser FastPageParser than there is no problem, but when using the new HTMLPageParser than is doesn't work.

How can we solve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

菊凝晚露 2025-01-08 05:50:03
<spring:message code="msg.x.x.x"  />

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

有几件事需要检查..

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

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

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

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

Works fine for me on decorators using FastPageParser.

A couple of things to check..

  • Are you including the springframework and sitemesh taglibs on your decorators?

  • I'm not sure if it will make a difference to the filter chain, but I'm using a custom configdecorator mapper that chooses the decorator based on a layout set in the request scope.

So in sitemesh.xml:

<decorator-mappers>
    <mapper class="org.x.x.CustomConfigDecoratorMapper">
        <param name="config" value="${decorators-file}" />
    </mapper>
</decorator-mappers>

CustomConfigDecoratorMapper look's like this:

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;
            }
        }
    }

Other than that.. have you considered using fmt:message instead?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文