org.thymeleaf.spring5.view.ThymeleafViewResolver Java Examples

The following examples show how to use org.thymeleaf.spring5.view.ThymeleafViewResolver. 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: WebConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ViewResolver viewResolver(SpringTemplateEngine engine) {
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setTemplateEngine(engine);
    resolver.setCharacterEncoding("UTF-8");
    resolver.setCache(false);
    return resolver;
}
 
Example #2
Source File: WebMvcConfig.java    From spring-comparing-template-engines with Apache License 2.0 5 votes vote down vote up
@Bean
public ViewResolver thymeleafViewResolver() {
	ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
	viewResolver.setViewNames(new String[] { "*-thymeleaf" });
	viewResolver.setTemplateEngine(thymeleafTemplateEngine());
	viewResolver.setCharacterEncoding("UTF-8");
	viewResolver.setCache(false);

	return viewResolver;
}
 
Example #3
Source File: WebMVCConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public ViewResolver plainViewResolver() {
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setTemplateEngine(templateEngine(plainTemplateResolver()));
    resolver.setContentType("text/plain");
    resolver.setCharacterEncoding("UTF-8");
    resolver.setViewNames(ArrayUtil.array("*.txt"));
    return resolver;
}
 
Example #4
Source File: WebMVCConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public ViewResolver javascriptViewResolver() {
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setTemplateEngine(templateEngine(javascriptTemplateResolver()));
    resolver.setContentType("application/javascript");
    resolver.setCharacterEncoding("UTF-8");
    resolver.setViewNames(ArrayUtil.array("*.js"));
    return resolver;
}
 
Example #5
Source File: WebMVCConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public ViewResolver htmlViewResolver() {
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setTemplateEngine(templateEngine(htmlTemplateResolver()));
    resolver.setContentType("text/html");
    resolver.setCharacterEncoding("UTF-8");
    resolver.setViewNames(ArrayUtil.array("*.html"));
    return resolver;
}
 
Example #6
Source File: WebConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public ViewResolver viewResolver() {
  ThymeleafViewResolver resolver = new ThymeleafViewResolver();
  resolver.setTemplateEngine(templateEngine());
  resolver.setCharacterEncoding("UTF-8");
  return resolver;
}
 
Example #7
Source File: WebAdminConfiguration.java    From wallride with Apache License 2.0 5 votes vote down vote up
@Bean
public ThymeleafViewResolver thymeleafViewResolver() {
	ThymeleafViewResolver viewResolver = new ExtendedThymeleafViewResolver();
	viewResolver.setTemplateEngine(templateEngine());
	viewResolver.setViewNames(this.properties.getViewNames());
	viewResolver.setCharacterEncoding(this.properties.getEncoding().name());
	viewResolver.setContentType(this.properties.getServlet().getContentType() + ";charset=" + this.properties.getEncoding());
	viewResolver.setCache(false);
	viewResolver.setOrder(1);
	return viewResolver;
}
 
Example #8
Source File: WallRideThymeleafConfiguration.java    From wallride with Apache License 2.0 5 votes vote down vote up
@Bean
public ThymeleafViewResolver thymeleafViewResolver(SpringTemplateEngine templateEngine) {
	ThymeleafViewResolver viewResolver = new ExtendedThymeleafViewResolver();
	viewResolver.setTemplateEngine(templateEngine);
	viewResolver.setViewNames(this.thymeleafProperties.getViewNames());
	viewResolver.setCharacterEncoding(this.thymeleafProperties.getEncoding().name());
	viewResolver.setContentType(this.thymeleafProperties.getServlet().getContentType() + ";charset=" + this.thymeleafProperties.getEncoding());
	viewResolver.setCache(false);
	viewResolver.setOrder(2);
	return viewResolver;
}
 
Example #9
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 #10
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 #11
Source File: ThymeleafConfiguration.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Bean
public ViewResolver getViewResolver(SpringTemplateEngine templateEngine) {
    ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
    viewResolver.setTemplateEngine(templateEngine);
    viewResolver.setCharacterEncoding("UTF-8");
    return viewResolver;
}
 
Example #12
Source File: SpringContextConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
@Bean(name="viewResolverThymeLeaf")
public ThymeleafViewResolver getViewResolverThyme(){
	ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); 
	viewResolver.setTemplateEngine(getTemplateEngine());
	viewResolver.setOrder(2);
	return viewResolver;
}
 
Example #13
Source File: SpringWebReactiveConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
@Bean(name="viewResolverThymeLeaf")
public ThymeleafViewResolver getViewResolverThyme(){
	ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); 
	viewResolver.setTemplateEngine(getTemplateEngine());
	viewResolver.setOrder(2);
	return viewResolver;
}
 
Example #14
Source File: SpringContextConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
@Bean(name="viewResolverThymeLeaf")
public ThymeleafViewResolver getViewResolverThyme(){
	ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); 
	viewResolver.setTemplateEngine(getTemplateEngine());
	viewResolver.setOrder(2);
	return viewResolver;
}
 
Example #15
Source File: ThymeleafRender.java    From Aooms with Apache License 2.0 5 votes vote down vote up
@Override
public void render(HttpServletResponse response, Object value) throws  Exception{
    // get ApplicationContext
    ApplicationContext ac1 = WebApplicationContextUtils.getRequiredWebApplicationContext(AoomsContext.getRequest().getServletContext());

    // get ThymeleafViewResolver Bean
    ThymeleafViewResolver resolver = (ThymeleafViewResolver) ac1.getBean("thymeleafViewResolver");
    View view = resolver.resolveViewName(mv.getViewName(), AoomsContext.getRequest().getLocale());
    view.render(mv.getModel(), AoomsContext.getRequest(), AoomsContext.getResponse());
}
 
Example #16
Source File: WebConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ViewResolver viewResolver(SpringTemplateEngine engine) {
    // 建立ViewResolver實作物件並設置模版引擎實例
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setTemplateEngine(engine);
    // 回應內容編碼
    resolver.setCharacterEncoding("UTF-8");
    resolver.setCache(false);
    return resolver;
}
 
Example #17
Source File: WebConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ViewResolver viewResolver(SpringTemplateEngine engine) {
    // 建立ViewResolver實作物件並設置模版引擎實例
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setTemplateEngine(engine);
    // 回應內容編碼
    resolver.setCharacterEncoding("UTF-8");
    resolver.setCache(false);
    return resolver;
}
 
Example #18
Source File: WebConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ViewResolver viewResolver(SpringTemplateEngine engine) {
    // 建立ViewResolver實作物件並設置模版引擎實例
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setTemplateEngine(engine);
    // 回應內容編碼
    resolver.setCharacterEncoding("UTF-8");
    resolver.setCache(false);
    return resolver;
}
 
Example #19
Source File: WebConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ViewResolver viewResolver(SpringTemplateEngine engine) {
    // 建立ViewResolver實作物件並設置模版引擎實例
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setTemplateEngine(engine);
    // 回應內容編碼
    resolver.setCharacterEncoding("UTF-8");
    resolver.setCache(false);
    return resolver;
}
 
Example #20
Source File: WebConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ViewResolver viewResolver(SpringTemplateEngine engine) {
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setTemplateEngine(engine);
    resolver.setCharacterEncoding("UTF-8");
    resolver.setCache(false);
    return resolver;
}
 
Example #21
Source File: WebConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ViewResolver viewResolver(SpringTemplateEngine engine) {
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setTemplateEngine(engine);
    resolver.setCharacterEncoding("UTF-8");
    resolver.setCache(false);
    return resolver;
}
 
Example #22
Source File: WebConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ViewResolver viewResolver(SpringTemplateEngine engine) {
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setTemplateEngine(engine);
    resolver.setCharacterEncoding("UTF-8");
    resolver.setCache(false);
    return resolver;
}
 
Example #23
Source File: WebConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ViewResolver viewResolver(SpringTemplateEngine engine) {
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setTemplateEngine(engine);
    resolver.setCharacterEncoding("UTF-8");
    resolver.setCache(false);
    return resolver;
}
 
Example #24
Source File: WebConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ViewResolver viewResolver(SpringTemplateEngine engine) {
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setTemplateEngine(engine);
    resolver.setCharacterEncoding("UTF-8");
    resolver.setCache(false);
    return resolver;
}
 
Example #25
Source File: WebConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean
public ViewResolver viewResolver(SpringTemplateEngine engine) {
    // 建立ViewResolver實作物件並設置模版引擎實例
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setTemplateEngine(engine);
    // 回應內容編碼
    resolver.setCharacterEncoding("UTF-8");
    resolver.setCache(false);
    return resolver;
}
 
Example #26
Source File: MvcWebConfig.java    From java-tutorial with MIT License 5 votes vote down vote up
/**
 * STEP 3 - 注册 Thymeleaf 视图解析器
 * 并为解析器注入模板引擎
 */
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
    ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
    viewResolver.setTemplateEngine(templateEngine());
    viewResolver.setCharacterEncoding("UTF-8");
    registry.viewResolver(viewResolver);
}
 
Example #27
Source File: ThymeleafViewsCacheInvalidationBean.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public void clearViewsCache() {
    ThymeleafViewResolver viewResolver = applicationContext.getBean(ThymeleafViewResolver.class);
    viewResolver.clearCache();
    viewResolver.getTemplateEngine().getConfiguration().getTemplateManager().clearCaches();
}
 
Example #28
Source File: ExclusiveViewResolverConfigurationTest.java    From spring-boot-web-support with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testExclusiveViewResolverConfiguration() {

    Assert.assertTrue(BeanUtils.isBeanPresent(applicationContext, ExclusiveViewResolverConfiguration.class));
    Assert.assertTrue(BeanUtils.isBeanPresent(applicationContext, ExclusiveViewResolverApplicationListener.class));

    ContentNegotiatingViewResolver contentNegotiatingViewResolver =
            applicationContext.getBean(ContentNegotiatingViewResolver.class);

    Assert.assertNotNull(contentNegotiatingViewResolver);

    List<ViewResolver> viewResolvers = contentNegotiatingViewResolver.getViewResolvers();

    Assert.assertEquals(1, viewResolvers.size());

    ThymeleafViewResolver thymeleafViewResolver =
            applicationContext.getBean("thymeleafViewResolver", ThymeleafViewResolver.class);

    Assert.assertEquals(thymeleafViewResolver, viewResolvers.get(0));

}
 
Example #29
Source File: ExclusiveViewResolverConfigurationDisabledTest.java    From spring-boot-web-support with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testExclusiveViewResolverConfigurationDisabled() {

    Assert.assertFalse(BeanUtils.isBeanPresent(applicationContext, ExclusiveViewResolverConfiguration.class));
    Assert.assertFalse(BeanUtils.isBeanPresent(applicationContext, ExclusiveViewResolverApplicationListener.class));

    ContentNegotiatingViewResolver contentNegotiatingViewResolver =
            applicationContext.getBean(ContentNegotiatingViewResolver.class);

    Assert.assertNotNull(contentNegotiatingViewResolver);

    List<ViewResolver> viewResolvers = contentNegotiatingViewResolver.getViewResolvers();

    Assert.assertTrue(viewResolvers.size() > 1);

    ThymeleafViewResolver thymeleafViewResolver =
            applicationContext.getBean("thymeleafViewResolver", ThymeleafViewResolver.class);

    Assert.assertTrue(viewResolvers.contains(thymeleafViewResolver));

}