2012-02-02 48 views
0

我們在Sitemesh 2的項目中使用spring:message標記。 在裝飾器中使用spring:消息時,不能識別-tag。我們可以在我們的jsp頁面中使用-tag,但可以在裝飾器jsp文件中使用。Sitemesh spring:在模板中未識別的消息

<?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
<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:消息呢?