Java Code Examples for org.thymeleaf.spring5.SpringTemplateEngine#addDialect()

The following examples show how to use org.thymeleaf.spring5.SpringTemplateEngine#addDialect() . 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: EmailMessageTemplateAutoConfiguration.java    From magic-starter with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean(MessageConstants.EMAIL_TEMPLATE_ENGINE_BEAN)
public TemplateEngine templateEngine(@Qualifier(MessageConstants.EMAIL_TEMPLATE_RESOLVER_BEAN) SpringResourceTemplateResolver templateResolver) {
	SpringTemplateEngine engine = new SpringTemplateEngine();
	engine.addDialect(new Java8TimeDialect());
	engine.addTemplateResolver(templateResolver);
	engine.getConfiguration();

	return engine;
}
 
Example 2
Source File: WebConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public SpringTemplateEngine templateEngine(ITemplateResolver templateResolver) {
    // 建立與設定模版引擎
    SpringTemplateEngine engine = new SpringTemplateEngine();
    engine.setEnableSpringELCompiler(true);
    engine.setTemplateResolver(templateResolver);
    engine.addDialect(new SpringSecurityDialect());
    return engine;
}
 
Example 3
Source File: SecurityDialectPostProcessor.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
@Override
public Object postProcessBeforeInitialization(
	Object bean, String beanName) throws BeansException {
	if (bean instanceof SpringTemplateEngine) {
		SpringTemplateEngine engine =
					(SpringTemplateEngine) bean;
		SecurityExpressionHandler<MethodInvocation> handler =
			applicationContext.getBean(
							SecurityExpressionHandler.class);
		SecurityDialect dialect = new SecurityDialect(handler);
		engine.addDialect(dialect);
	}
	return bean;
}
 
Example 4
Source File: SecurityDialectPostProcessor.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
@Override
public Object postProcessBeforeInitialization(
	Object bean, String beanName) throws BeansException {
	if (bean instanceof SpringTemplateEngine) {
		SpringTemplateEngine engine =
					(SpringTemplateEngine) bean;
		SecurityExpressionHandler<MethodInvocation> handler =
			applicationContext.getBean(
							SecurityExpressionHandler.class);
		SecurityDialect dialect = new SecurityDialect(handler);
		engine.addDialect(dialect);
	}
	return bean;
}
 
Example 5
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 6
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 7
Source File: WebConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public ISpringTemplateEngine templateEngine() {
  SpringTemplateEngine engine = new SpringTemplateEngine();
  engine.setEnableSpringELCompiler(true);
  engine.setTemplateResolver(templateResolver());
  engine.addDialect(new SpringSecurityDialect());
  return engine;
}
 
Example 8
Source File: WebMVCConfig.java    From tutorials with MIT License 5 votes vote down vote up
private ISpringTemplateEngine templateEngine(ITemplateResolver templateResolver) {
    SpringTemplateEngine engine = new SpringTemplateEngine();
    engine.addDialect(new LayoutDialect(new GroupingStrategy()));
    engine.addDialect(new Java8TimeDialect());
    engine.setTemplateResolver(templateResolver);
    engine.setTemplateEngineMessageSource(messageSource());
    return engine;
}