Reputation: 11
We have a basic java web application using springboot(ver 1.5) & maven. We are using thymeleaf and dandelion for the presentation layer. Dandelion was added so we can use datatables. The datatables are working fine, they are sortable, searchable, etc. The only problem is that the export to excel function does not work(null pointer when clicking the xslx link). I have followed the tutorial found here.
https://dandelion.github.io/components/datatables/1.1.0/docs/html/#6-4-activating-export
One difference in the example code and my implementation is that I am using springboot and do not have a web.xml file. I assume my issue may be in the config file where the filter is setup. Anyone see any issue with this. Also, please share your config file if using dandelion excel export in springboot app. Thanks!
DandelionConfiguration.java file:
package com.gatewaysvc.configuration;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.github.dandelion.core.web.DandelionFilter;
import com.github.dandelion.core.web.DandelionServlet;
import com.github.dandelion.datatables.core.web.filter.DatatablesFilter;
import com.github.dandelion.datatables.thymeleaf.dialect.DataTablesDialect;
import com.github.dandelion.thymeleaf.dialect.DandelionDialect;
@Configuration
public class DandelionConfiguration {
@Bean
public DandelionDialect dandelionDialect()
{
return new DandelionDialect();
}
@Bean
public DataTablesDialect dataTablesDialect()
{
return new DataTablesDialect();
}
// Dandelion filter definition and mapping
@Bean
public FilterRegistrationBean filterRegistrationBean()
{
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(new DandelionFilter());
filterRegistrationBean.addUrlPatterns("/*");
return filterRegistrationBean;
}
//Dandelion servlet definition and mapping
@Bean
public ServletRegistrationBean servletRegistrationBean()
{
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean();
servletRegistrationBean.setServlet(new DandelionServlet());
servletRegistrationBean.addUrlMappings("/dandelion-assets/*");
servletRegistrationBean.setName("dandelionServlet");
return servletRegistrationBean;
}
@Bean
public DatatablesFilter dataTablesFilter () {
return new DatatablesFilter();
}
}
html page snippet:
<div class="container" id="dataTables">
<div th:if="${not #lists.isEmpty(deviceActivityFormBean.inbound) and #lists.isEmpty(deviceActivityFormBean.outbound) and #lists.isEmpty(deviceActivityFormBean.both)}" class="panel panel-primary">
<div class="panel-body">
<table class="table display table-striped table-hover cell-border" dt:table="true" id="deviceInboundTable" dt:export="xlsx">
<thead>
<tr>
<th>Device Id 000</th>
<th>Create TMSTP</th>
<th>Message</th>
<th>IP Address</th>
<th>HTTP Resp Code</th>
<th>Server</th>
<th>Duration (ms)</th>
<th>Protocol</th>
</tr>
</thead>
<tbody>
<tr th:each="dvc : ${deviceActivityFormBean.inbound}">
<td dt:xlsx="${dvc.deviceId}" th:text="${dvc.deviceId}"></td>
<td th:text="${dvc.createTime}"></td>
<td id ="mssgInbound" th:text="${dvc.mssg}"></td>
<td th:text="${dvc.ipMssg}"></td>
<td th:text="${dvc.httpResp}"></td>
<td th:text="${dvc.server}"></td>
<td th:text="${dvc.duration}"></td>
<td th:text="${dvc.protocol}"></td>
</tr>
</tbody>
</table>
</div>
<div>
Upvotes: 1
Views: 122