Fix #171 Jetty 9 support by removing Dandelion

This commit is contained in:
Antoine Rey 2016-10-07 18:21:09 +02:00
parent d5571c0fe4
commit 377ef7e500
6 changed files with 73 additions and 109 deletions

28
pom.xml
View file

@ -30,10 +30,6 @@
<!-- Others --> <!-- Others -->
<mysql-driver.version>5.1.36</mysql-driver.version> <mysql-driver.version>5.1.36</mysql-driver.version>
<!-- Web dependencies -->
<dandelion.version>1.1.1</dandelion.version>
<dandelion.datatables.version>1.1.0</dandelion.datatables.version>
<cobertura.version>2.7</cobertura.version> <cobertura.version>2.7</cobertura.version>
<jpa.database>HSQL</jpa.database> <jpa.database>HSQL</jpa.database>
@ -85,6 +81,14 @@
<artifactId>taglibs-standard-jstlel</artifactId> <artifactId>taglibs-standard-jstlel</artifactId>
</dependency> </dependency>
<!-- JSon --> <!-- JSon -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.jayway.jsonpath</groupId> <groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId> <artifactId>json-path</artifactId>
@ -218,22 +222,6 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- Dandelion -->
<dependency>
<groupId>com.github.dandelion</groupId>
<artifactId>dandelion-jsp</artifactId>
<version>${dandelion.version}</version>
</dependency>
<dependency>
<groupId>com.github.dandelion</groupId>
<artifactId>datatables-jsp</artifactId>
<version>${dandelion.datatables.version}</version>
</dependency>
<dependency>
<groupId>com.github.dandelion</groupId>
<artifactId>datatables-export-itext</artifactId>
<version>${dandelion.datatables.version}</version>
</dependency>
<!-- temporary fix: below dependency should not be necessary as it is a transitive dependency. <!-- temporary fix: below dependency should not be necessary as it is a transitive dependency.
For some reason we can't build the app unless it is a first level dependency --> For some reason we can't build the app unless it is a first level dependency -->
<dependency> <dependency>

View file

@ -107,15 +107,6 @@ File -> Import -> Maven -> Existing Maven project
<a href="/src/main/webapp/WEB-INF/jsp/fragments/staticFiles.jsp#L12">sample usage in JSP</a></td> <a href="/src/main/webapp/WEB-INF/jsp/fragments/staticFiles.jsp#L12">sample usage in JSP</a></td>
</td> </td>
</tr> </tr>
<tr>
<td>Dandelion-datatables</td>
<td>
<a href="/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp">ownersList.jsp</a>
<a href="/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp">vetList.jsp</a>
<a href="/src/main/java/org/springframework/samples/petclinic/PetclinicInitializer.java">PetclinicInitializer.java</a>
<a href="/src/main/resources/dandelion/datatables/datatables.properties">datatables.properties</a>
</td>
</tr>
<tr> <tr>
<td>Thymeleaf branch</td> <td>Thymeleaf branch</td>
<td> <td>

View file

@ -15,19 +15,14 @@
*/ */
package org.springframework.samples.petclinic; package org.springframework.samples.petclinic;
import com.github.dandelion.core.web.DandelionFilter;
import com.github.dandelion.core.web.DandelionServlet;
import com.github.dandelion.datatables.core.web.filter.DatatablesFilter;
import org.springframework.util.Assert;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.XmlWebApplicationContext; import org.springframework.web.context.support.XmlWebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer; import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;
import javax.servlet.*; import javax.servlet.Filter;
import java.util.EnumSet; import javax.servlet.ServletContext;
/** /**
@ -35,8 +30,8 @@ import java.util.EnumSet;
* {@link ServletContext} programmatically. * {@link ServletContext} programmatically.
* <p/> * <p/>
* Create the Spring "<strong>root</strong>" application context.<br/> * Create the Spring "<strong>root</strong>" application context.<br/>
* Register a {@link DispatcherServlet} and a {@link DandelionServlet} in the servlet context.<br/> * Register a {@link DispatcherServlet} in the servlet context.<br/>
* For both servlets, register a {@link CharacterEncodingFilter}, a {@link DandelionFilter} an a {@link DatatablesFilter}. * For both servlets, register a {@link CharacterEncodingFilter}.
* <p/> * <p/>
* *
* @author Antoine Rey * @author Antoine Rey
@ -52,14 +47,6 @@ public class PetclinicInitializer extends AbstractDispatcherServletInitializer {
*/ */
private static final String SPRING_PROFILE = "jpa"; private static final String SPRING_PROFILE = "jpa";
private static final String DANDELION_SERVLET = "dandelionServlet";
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
registerDandelionServlet(servletContext);
}
@Override @Override
protected WebApplicationContext createRootApplicationContext() { protected WebApplicationContext createRootApplicationContext() {
XmlWebApplicationContext rootAppContext = new XmlWebApplicationContext(); XmlWebApplicationContext rootAppContext = new XmlWebApplicationContext();
@ -68,7 +55,6 @@ public class PetclinicInitializer extends AbstractDispatcherServletInitializer {
return rootAppContext; return rootAppContext;
} }
@Override @Override
protected WebApplicationContext createServletApplicationContext() { protected WebApplicationContext createServletApplicationContext() {
XmlWebApplicationContext webAppContext = new XmlWebApplicationContext(); XmlWebApplicationContext webAppContext = new XmlWebApplicationContext();
@ -85,27 +71,7 @@ public class PetclinicInitializer extends AbstractDispatcherServletInitializer {
protected Filter[] getServletFilters() { protected Filter[] getServletFilters() {
// Used to provide the ability to enter Chinese characters inside the Owner Form // Used to provide the ability to enter Chinese characters inside the Owner Form
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter("UTF-8", true); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter("UTF-8", true);
return new Filter[]{characterEncodingFilter};
// Dandelion filter definition and mapping -->
DandelionFilter dandelionFilter = new DandelionFilter();
// Dandelion-Datatables filter, used for basic export -->
DatatablesFilter datatablesFilter = new DatatablesFilter();
return new Filter[]{characterEncodingFilter, dandelionFilter, datatablesFilter};
} }
@Override
protected FilterRegistration.Dynamic registerServletFilter(ServletContext servletContext, Filter filter) {
FilterRegistration.Dynamic registration = super.registerServletFilter(servletContext, filter);
registration.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE), false, DANDELION_SERVLET);
return registration;
}
private void registerDandelionServlet(ServletContext servletContext) {
DandelionServlet dandelionServlet = new DandelionServlet();
ServletRegistration.Dynamic registration = servletContext.addServlet(DANDELION_SERVLET, dandelionServlet);
registration.setLoadOnStartup(2);
registration.addMapping("/dandelion-assets/*");
}
} }

View file

@ -1,6 +0,0 @@
# ==================================
# Dandelion-Datatables configuration
# ==================================
# Disable the asset management of Dandelion-Core for all non-DataTable-related assets
main.standalone=true

View file

@ -3,31 +3,46 @@
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="datatables" uri="http://github.com/dandelion/datatables" %>
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
<petclinic:layout pageName="owners"> <petclinic:layout pageName="owners">
<h2>Owners</h2> <h2>Owners</h2>
<datatables:table id="owners" data="${selections}" row="owner" <table id="vets" class="table table-striped">
cssClass="table table-striped" pageable="false" info="false" export="pdf"> <thead>
<datatables:column title="Name" cssStyle="width: 150px;" display="html"> <tr>
<th style="width: 150px;">Name</th>
<th style="width: 200px;">Address</th>
<th>City</th>
<th style="width: 120px">Telephone</th>
<th>Pets</th>
</tr>
</thead>
<tbody>
<c:forEach items="${selections}" var="owner">
<tr>
<td>
<spring:url value="/owners/{ownerId}.html" var="ownerUrl"> <spring:url value="/owners/{ownerId}.html" var="ownerUrl">
<spring:param name="ownerId" value="${owner.id}"/> <spring:param name="ownerId" value="${owner.id}"/>
</spring:url> </spring:url>
<a href="${fn:escapeXml(ownerUrl)}"><c:out value="${owner.firstName} ${owner.lastName}"/></a> <a href="${fn:escapeXml(ownerUrl)}"><c:out value="${owner.firstName} ${owner.lastName}"/></a>
</datatables:column> </td>
<datatables:column title="Name" display="pdf"> <td>
<c:out value="${owner.firstName} ${owner.lastName}"/> <c:out value="${owner.address}"/>
</datatables:column> </td>
<datatables:column title="Address" property="address" cssStyle="width: 200px;"/> <td>
<datatables:column title="City" property="city"/> <c:out value="${owner.city}"/>
<datatables:column title="Telephone" property="telephone"/> </td>
<datatables:column title="Pets" cssStyle="width: 100px;"> <td>
<c:out value="${owner.telephone}"/>
</td>
<td>
<c:forEach var="pet" items="${owner.pets}"> <c:forEach var="pet" items="${owner.pets}">
<c:out value="${pet.name} "/> <c:out value="${pet.name} "/>
</c:forEach> </c:forEach>
</datatables:column> </td>
<datatables:export type="pdf" cssClass="btn" cssStyle="height: 25px;"/> </tr>
</datatables:table> </c:forEach>
</tbody>
</table>
</petclinic:layout> </petclinic:layout>

View file

@ -2,24 +2,34 @@
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="datatables" uri="http://github.com/dandelion/datatables" %>
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %> <%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
<petclinic:layout pageName="vets"> <petclinic:layout pageName="vets">
<h2>Veterinarians</h2> <h2>Veterinarians</h2>
<datatables:table id="vets" data="${vets.vetList}" row="vet" cssClass="table table-striped" <table id="vets" class="table table-striped">
pageable="false" info="false"> <thead>
<datatables:column title="Name"> <tr>
<th>Name</th>
<th>Specialties</th>
</tr>
</thead>
<tbody>
<c:forEach items="${vets.vetList}" var="vet">
<tr>
<td>
<c:out value="${vet.firstName} ${vet.lastName}"/> <c:out value="${vet.firstName} ${vet.lastName}"/>
</datatables:column> </td>
<datatables:column title="Specialties"> <td>
<c:forEach var="specialty" items="${vet.specialties}"> <c:forEach var="specialty" items="${vet.specialties}">
<c:out value="${specialty.name} "/> <c:out value="${specialty.name} "/>
</c:forEach> </c:forEach>
<c:if test="${vet.nrOfSpecialties == 0}">none</c:if> <c:if test="${vet.nrOfSpecialties == 0}">none</c:if>
</datatables:column> </td>
</datatables:table> </tr>
</c:forEach>
</tbody>
</table>
<table class="table-buttons"> <table class="table-buttons">
<tr> <tr>