Thymeleaf で Spring Boot を使用していて、Dandelion データテーブルを追加したいのですが、うまくいきません。
これが私のmaven依存関係です:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Dandelion -->
<dependency>
<groupId>com.github.dandelion</groupId>
<artifactId>datatables-thymeleaf</artifactId>
<version>0.10.1</version>
</dependency>
このガイドhttp://dandelion.github.io/dandelion/docs/installation/thymeleaf.htmlに従っており、次の Bean を構成しています。
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public FilterRegistrationBean dandelion() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(new DandelionFilter());
registrationBean.addUrlPatterns("/*");
return registrationBean;
}
@Bean
public ServletRegistrationBean dandelionServlet() {
ServletRegistrationBean registrationBean = new ServletRegistrationBean();
registrationBean.setServlet(new DandelionServlet());
registrationBean.addUrlMappings("/dandelion/*");
return registrationBean;
}
@Bean
public ServletContextTemplateResolver defaultTemplateResolver() {
ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
resolver.setTemplateMode("HTML5");
resolver.setPrefix("/WEB-INF/templates/");
resolver.setSuffix(".html");
resolver.setCharacterEncoding("UTF-8");
resolver.setCacheable(false);
SpringTemplateEngine engine = new SpringTemplateEngine();
engine.setTemplateResolver(resolver);
engine.addDialect(new DataTablesDialect());
return resolver;
}
}
テスト用にこの HTML を作成しました。
<!doctype html>
<html
xmlns:th="http://www.thymeleaf.org"
xmlns:ddl="http://github.com/dandelion">
<head>
<link type="text/css" href="/stylesheets/dataTables.css" media="screen" rel="stylesheet" />
<script src="/javascripts/vendor/jquery191.js" type="text/javascript"></script>
<script src="/javascripts/vendor/dataTables.js" type="text/javascript"></script>
</head>
<body>
<br/>
<table id="myTableId" ddl:table="true" ddl:url="@{/clientes}">
<thead>
<tr>
<th ddl:property="telefone">Telefone</th>
<th ddl:property="nome">Nome</th>
</tr>
</thead>
</table>
</body>
</html>
Dandelion のサーブレットは呼び出されていないと思います。名前空間は処理されません。