org.thymeleaf.templateresolver.ServletContextTemplateResolver Java Examples

The following examples show how to use org.thymeleaf.templateresolver.ServletContextTemplateResolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetadataServlet.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void init() {
  // Setup ThymeLeaf
  ServletContextTemplateResolver templateResolver =
      new ServletContextTemplateResolver(this.getServletContext());

  templateResolver.setPrefix("/WEB-INF/templates/");
  templateResolver.setSuffix(".html");
  templateResolver.setCacheTTLMs(Long.valueOf(1200000L)); // TTL=20m

  // Cache is set to true by default. Set to false if you want templates to
  // be automatically updated when modified.
  templateResolver.setCacheable(true);

  templateEngine = new TemplateEngine();
  templateEngine.setTemplateResolver(templateResolver);
}
 
Example #2
Source File: GaeInfoServlet.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void init() {
  // Setup ThymeLeaf
  ServletContextTemplateResolver templateResolver =
      new ServletContextTemplateResolver(this.getServletContext());

  templateResolver.setPrefix("/WEB-INF/templates/");
  templateResolver.setSuffix(".html");
  templateResolver.setCacheTTLMs(Long.valueOf(1200000L)); // TTL=20m

  // Cache is set to true by default. Set to false if you want templates to
  // be automatically updated when modified.
  templateResolver.setCacheable(true);

  templateEngine = new TemplateEngine();
  templateEngine.setTemplateResolver(templateResolver);
}
 
Example #3
Source File: GaeInfoServlet.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void init() {
  // Setup ThymeLeaf
  ServletContextTemplateResolver templateResolver =
      new ServletContextTemplateResolver(this.getServletContext());

  templateResolver.setPrefix("/WEB-INF/templates/");
  templateResolver.setSuffix(".html");
  templateResolver.setCacheTTLMs(1200000L); // TTL=20m

  // Cache is set to true by default. Set to false if you want templates to
  // be automatically updated when modified.
  templateResolver.setCacheable(true);

  templateEngine = new TemplateEngine();
  templateEngine.setTemplateResolver(templateResolver);
}
 
Example #4
Source File: GaeInfoServlet.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void init() {
  // Setup ThymeLeaf
  ServletContextTemplateResolver templateResolver =
      new ServletContextTemplateResolver(this.getServletContext());

  templateResolver.setPrefix("/WEB-INF/templates/");
  templateResolver.setSuffix(".html");
  templateResolver.setCacheTTLMs(Long.valueOf(1200000L)); // TTL=20m

  // Cache is set to true by default. Set to false if you want templates to
  // be automatically updated when modified.
  templateResolver.setCacheable(true);

  templateEngine = new TemplateEngine();
  templateEngine.setTemplateResolver(templateResolver);
}
 
Example #5
Source File: DefaultTemplateEngineProducer.java    From krazo with Apache License 2.0 5 votes vote down vote up
@Produces
@ViewEngineConfig
public TemplateEngine getTemplateEngine() {

    ITemplateResolver resolver = new ServletContextTemplateResolver(this.servletContext);

    TemplateEngine engine = new TemplateEngine();
    engine.setTemplateResolver(resolver);
    return engine;

}
 
Example #6
Source File: WebConfig.java    From spring4-sandbox with Apache License 2.0 5 votes vote down vote up
private ServletContextTemplateResolver templateResolver() {
	ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
    resolver.setPrefix("/WEB-INF/templates/");
    resolver.setSuffix(".html");	
    resolver.setTemplateMode("HTML5");
    resolver.setCacheable(false);
    return resolver;
}
 
Example #7
Source File: MVCConfig.java    From convergent-ui with Apache License 2.0 5 votes vote down vote up
@Bean
public ThymeleafViewResolver thymeleafViewResolver(WebApplicationContext wac) {
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(wac.getServletContext());
    templateResolver.setPrefix("/WEB-INF/templates/");
    templateResolver.setSuffix(".html");
    templateResolver.setTemplateMode("HTML");
    templateResolver.setCharacterEncoding("UTF-8");
    templateEngine.setTemplateResolver(templateResolver);
    resolver.setTemplateEngine(templateEngine);
    resolver.setOrder(2);
    resolver.setApplicationContext(wac);
    resolver.setCharacterEncoding("UTF-8");

    //Enable the Spring Security Thymeleaf integration
    templateEngine.addDialect(new LayoutDialect());

    // caching
    String[] activeProfiles = env.getActiveProfiles();
    if (Arrays.asList(activeProfiles).contains("dev")) {
        log.info("DEV Profile is active. Disabling template caching.");
        templateResolver.setCacheable(false);
        templateEngine.setCacheManager(null);
        resolver.setCache(false);
    }
    return resolver;
}
 
Example #8
Source File: MVCConfig.java    From convergent-ui with Apache License 2.0 5 votes vote down vote up
@Bean
public ThymeleafViewResolver thymeleafViewResolver(WebApplicationContext wac) {
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(wac.getServletContext());
    templateResolver.setPrefix("/WEB-INF/templates/");
    templateResolver.setSuffix(".html");
    templateResolver.setTemplateMode("HTML");
    templateResolver.setCharacterEncoding("UTF-8");
    templateEngine.setTemplateResolver(templateResolver);
    resolver.setTemplateEngine(templateEngine);
    resolver.setOrder(2);
    resolver.setApplicationContext(wac);
    resolver.setCharacterEncoding("UTF-8");

    //Enable the Spring Security Thymeleaf integration
    templateEngine.addDialect(new LayoutDialect());

    // caching
    String[] activeProfiles = env.getActiveProfiles();
    if (Arrays.asList(activeProfiles).contains("dev")) {
        log.info("DEV Profile is active. Disabling template caching.");
        templateResolver.setCacheable(false);
        templateEngine.setCacheManager(null);
        resolver.setCache(false);
    }
    return resolver;
}
 
Example #9
Source File: DefaultTemplateEngineProducer.java    From ozark with Apache License 2.0 5 votes vote down vote up
@Produces
@ViewEngineConfig
public TemplateEngine getTemplateEngine() {

    ITemplateResolver resolver = new ServletContextTemplateResolver(this.servletContext);

    TemplateEngine engine = new TemplateEngine();
    engine.setTemplateResolver(resolver);
    return engine;

}
 
Example #10
Source File: ThymeleafConfig.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
@Bean
    public SpringTemplateEngine templateEngine(final ServletContextTemplateResolver templateResolver) {
        SpringTemplateEngine engine = new SpringTemplateEngine();
        engine.setTemplateResolver(templateResolver);
//        engine.setEnableSpringELCompiler(true);

        engine.setAdditionalDialects(new HashSet<IDialect>() {{
            add(new LayoutDialect());
            add(new SpringSecurityDialect());
        }});
        return engine;
    }
 
Example #11
Source File: ThymeleafConfig.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
@Bean
public ServletContextTemplateResolver templateResolver() {
    ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
    resolver.setPrefix("/WEB-INF/templates/");
    resolver.setSuffix(".html");
    resolver.setTemplateMode("HTML5");
    resolver.setCacheable(false);
    resolver.setOrder(1);
    return resolver;
}
 
Example #12
Source File: ThymeleafConfig.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
@Bean
public ServletContextTemplateResolver templateResolver() {
    ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
    resolver.setPrefix("/WEB-INF/templates/");
    resolver.setSuffix(".html");
    resolver.setTemplateMode("HTML5");
    resolver.setCacheable(false);
    resolver.setOrder(1);
    return resolver;
}
 
Example #13
Source File: ThymeleafConfig.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
@Bean
public ServletContextTemplateResolver templateResolver() {
    ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
    resolver.setPrefix("/WEB-INF/templates/");
    resolver.setSuffix(".html");
    resolver.setTemplateMode("HTML5");
    resolver.setCacheable(false);
    resolver.setOrder(1);
    return resolver;
}
 
Example #14
Source File: ThymeleafConfig.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
@Bean
public ServletContextTemplateResolver templateResolver() {
    ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
    resolver.setPrefix("/WEB-INF/templates/");
    resolver.setSuffix(".html");
    resolver.setTemplateMode("HTML5");
    resolver.setCacheable(false);
    resolver.setOrder(1);
    return resolver;
}
 
Example #15
Source File: ThymeleafConfig.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
@Bean
    public SpringTemplateEngine templateEngine(final ServletContextTemplateResolver templateResolver) {
        SpringTemplateEngine engine = new SpringTemplateEngine();
        engine.setTemplateResolver(templateResolver);
//        engine.setEnableSpringELCompiler(true);

        engine.setAdditionalDialects(new HashSet<IDialect>() {{
            add(new LayoutDialect());
            add(new SpringSecurityDialect());
        }});
        return engine;
    }
 
Example #16
Source File: ThymeleafConfig.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
@Bean
public ServletContextTemplateResolver templateResolver() {
    ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
    resolver.setPrefix("/WEB-INF/templates/");
    resolver.setSuffix(".html");
    resolver.setTemplateMode("HTML5");
    resolver.setCacheable(false);
    resolver.setOrder(1);
    return resolver;
}
 
Example #17
Source File: ThymeleafConfig.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
@Bean
    public SpringTemplateEngine templateEngine(final ServletContextTemplateResolver templateResolver) {
        SpringTemplateEngine engine = new SpringTemplateEngine();
        engine.setTemplateResolver(templateResolver);
//        engine.setEnableSpringELCompiler(true);

        engine.setAdditionalDialects(new HashSet<IDialect>() {{
            add(new LayoutDialect());
            add(new SpringSecurityDialect());
        }});
        return engine;
    }
 
Example #18
Source File: ThymeleafConfig.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
@Bean
    public ServletContextTemplateResolver templateResolver() {
        ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
        resolver.setPrefix("/WEB-INF/templates/");
        resolver.setSuffix(".html");
//        resolver.setTemplateMode("HTML5");
        resolver.setCacheable(false);
        resolver.setOrder(1);
        return resolver;
    }
 
Example #19
Source File: ThymeleafConfig.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
@Bean
    public SpringTemplateEngine templateEngine(final ServletContextTemplateResolver templateResolver) {
        SpringTemplateEngine engine = new SpringTemplateEngine();
        engine.setTemplateResolver(templateResolver);
//        engine.setEnableSpringELCompiler(true);

        engine.setAdditionalDialects(new HashSet<IDialect>() {{
            add(new LayoutDialect());
            add(new SpringSecurityDialect());
        }});
        return engine;
    }
 
Example #20
Source File: ThymeleafConfig.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
@Bean
public ServletContextTemplateResolver templateResolver() {
    ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
    resolver.setPrefix("/WEB-INF/templates/");
    resolver.setSuffix(".html");
    resolver.setTemplateMode("HTML5");
    resolver.setCacheable(false);
    resolver.setOrder(1);
    return resolver;
}
 
Example #21
Source File: ThymeleafConfig.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
@Bean
public ServletContextTemplateResolver templateResolver() {
    ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
    resolver.setPrefix("/WEB-INF/templates/");
    resolver.setSuffix(".html");
    resolver.setTemplateMode("HTML5");
    resolver.setCacheable(false);
    resolver.setOrder(1);
    return resolver;
}
 
Example #22
Source File: ThymeleafViewEngine.java    From generator-jvm with MIT License 5 votes vote down vote up
@PostConstruct
public void postConstruct() {
  final ServletContextTemplateResolver resolver = new ServletContextTemplateResolver(servletContext);
  resolver.setPrefix("/WEB-INF/layouts/");
  resolver.setSuffix(".html");
  resolver.setTemplateMode(TemplateMode.HTML);
  resolver.setCacheable(false);
  engine = new TemplateEngine();
  engine.setTemplateResolver(resolver);
}
 
Example #23
Source File: ThymeleafConfig.java    From Spring-Security-Third-Edition with MIT License 4 votes vote down vote up
@Bean
public SpringTemplateEngine templateEngine(final ServletContextTemplateResolver templateResolver) {
    SpringTemplateEngine engine = new SpringTemplateEngine();
    engine.setTemplateResolver(templateResolver);
    return engine;
}
 
Example #24
Source File: ThymeleafConfig.java    From Spring-Security-Third-Edition with MIT License 4 votes vote down vote up
@Bean
public SpringTemplateEngine templateEngine(final ServletContextTemplateResolver templateResolver) {
    SpringTemplateEngine engine = new SpringTemplateEngine();
    engine.setTemplateResolver(templateResolver);
    return engine;
}
 
Example #25
Source File: ThymeleafConfig.java    From Spring-Security-Third-Edition with MIT License 4 votes vote down vote up
@Bean
public SpringTemplateEngine templateEngine(final ServletContextTemplateResolver templateResolver) {
    SpringTemplateEngine engine = new SpringTemplateEngine();
    engine.setTemplateResolver(templateResolver);
    return engine;
}
 
Example #26
Source File: ThymeleafConfig.java    From Spring-Security-Third-Edition with MIT License 4 votes vote down vote up
@Bean
public SpringTemplateEngine templateEngine(final ServletContextTemplateResolver templateResolver) {
    SpringTemplateEngine engine = new SpringTemplateEngine();
    engine.setTemplateResolver(templateResolver);
    return engine;
}