2016-05-19 14 views
3

Thymeleaf 3は何とかTiles 2をサポートしていますか?そこ私はThumeleaf 2.xxのthymeleaf-extras-tiles2-spring4のために使用したパッケージですが、私は今見るとorg.thymeleaf.dialect.AbstractDialectクラスの変化Thymeleaf 3とTiles2の統合

Caused by: java.lang.NoSuchMethodError: org.thymeleaf.dialect.AbstractDialect: method <init>()V not found 
[INFO] at org.thymeleaf.extras.tiles2.dialect.TilesDialect.<init>(TilesDialect.java:46) 

の私ができるようにするには、この統合の更新を待つ必要がないので、それは互換性がありません。 T3から始めるには?

私はこのような何かのために私のタイルを使用し、私はThymeleaf3

にタイルをシミュレートすることができますどのような方法があります:

<definition name="portal/**" template="layouts/portal"> 
    <put-attribute name="_head" value="/portal/{1} :: _head"/> 
    <put-attribute name="content" value="/portal/{1} :: content"/> 
    </definition> 
+0

任意のソリューションを見つけましたか? –

+1

解決策を受け付けた回答として投稿しました。それが役に立てば幸い。 –

答えて

0

私はSpringTemplateEngineのプロキシを作成し、TemplateEngine.process()を助言しているという問題を解決するためには、方法。

は仕組み:

コードマップレイアウトを、例えばテンプレート経路に基づい:

portal/moje_konto/moje_dane 

LAYOUTS_PATH/portal 

さらにレイアウトにマッピングされ、それは可変通過します実際のテンプレートへのパスを含むVIEW

レイアウト内には、特定のフラグメントを含めるために使用できます。 非常にシンプルなポータルレイアウトは、次のようになります。

<!DOCTYPE html SYSTEM "about:legacy-compat"> 
<html lang="pl" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.springframework.org/security/tags"> 
    <body> 
     <div th:replace="${'portal/' + VIEW} :: content">Content</div> 
    </body> 
</html> 

コントローラーを:

@PreAuthorize("isAuthenticated()") 
    @RequestMapping(value = "/", method = RequestMethod.GET) 
    public String home(Model model) { 

    return "portal/home/index"; 
    } 

TemplateEngine:

public class LayoutTemplateEngine implements ITemplateEngine, MessageSourceAware, InitializingBean { 

    private final Logger logger = Logger.getLogger(this.getClass().getName()); 

    private final String LAYOUTS_PATH = "layouts/"; 

    private final SpringTemplateEngine templateEngine = new SpringTemplateEngine(); 

    @Override 
    public void process(TemplateSpec templateSpec, IContext context, Writer writer) { 
    String template = templateSpec.getTemplate(); 

    logger.info("Rendering template: " + template); 

    if (context instanceof WebExpressionContext) { 
     int end = template.indexOf("/"); 
     if (end != -1) { 
     // change template 
     templateSpec = new TemplateSpec(LAYOUTS_PATH + template.substring(0, end), templateSpec.getTemplateSelectors(), templateSpec.getTemplateMode(), templateSpec.getTemplateResolutionAttributes()); 
     // add VIEW variable 
     ((WebExpressionContext)context).setVariable("VIEW", template.substring(end + 1)); 
     } 
    } 

    templateEngine.process(templateSpec, context, writer); 
    logger.info("Rendering finished"); 
    } 

    public void setTemplateResolver(final ITemplateResolver templateResolver) { 
    templateEngine.setTemplateResolver(templateResolver); 
    } 

    public void setEnableSpringELCompiler(final boolean enableSpringELCompiler) { 
    templateEngine.setEnableSpringELCompiler(enableSpringELCompiler); 
    } 

    public void addDialect(final IDialect dialect) { 
    templateEngine.addDialect(dialect); 
    } 

    public void addTemplateResolver(final ITemplateResolver templateResolver) { 
    templateEngine.addTemplateResolver(templateResolver); 
    } 

    @Override 
    public IEngineConfiguration getConfiguration() { 
    return templateEngine.getConfiguration(); 
    } 

    @Override 
    public String process(String template, IContext context) { 
    return process(new TemplateSpec(template, null, null, null), context); 
    } 

    @Override 
    public String process(String template, Set<String> templateSelectors, IContext context) { 
    return process(new TemplateSpec(template, templateSelectors, null, null), context); 
    } 

    @SuppressWarnings("resource") 
    @Override 
    public String process(TemplateSpec templateSpec, IContext context) { 
    final Writer stringWriter = new FastStringWriter(100); 
    process(templateSpec, context, stringWriter); 
    return stringWriter.toString(); 
    } 

    @Override 
    public void process(String template, IContext context, Writer writer) { 
    process(new TemplateSpec(template, null, null, null), context, writer); 
    } 

    @Override 
    public void process(String template, Set<String> templateSelectors, IContext context, Writer writer) { 
    process(new TemplateSpec(template, templateSelectors, null, null), context, writer); 
    } 

    @Override 
    public IThrottledTemplateProcessor processThrottled(String template, IContext context) { 
    return processThrottled(new TemplateSpec(template, null, null, null), context); 
    } 

    @Override 
    public IThrottledTemplateProcessor processThrottled(String template, Set<String> templateSelectors, IContext context) { 
    return processThrottled(new TemplateSpec(template, templateSelectors, null, null), context); 
    } 

    @Override 
    public IThrottledTemplateProcessor processThrottled(TemplateSpec templateSpec, IContext context) { 
    return templateEngine.processThrottled(templateSpec, context); 
    } 

    @Override 
    public void afterPropertiesSet() throws Exception { 
    templateEngine.afterPropertiesSet(); 
    } 

    @Override 
    public void setMessageSource(MessageSource messageSource) { 
    templateEngine.setMessageSource(messageSource); 
    } 
}