1. Stephan Oudmaijer
  2. cloudministratie

Commits

Stephan Oudmaijer  committed dd9e67b

Integrated tiles2 with velocity.

  • Participants
  • Parent commits 973afb5
  • Branches master

Comments (0)

Files changed (5)

File pom.xml

View file
             <artifactId>groovy-all</artifactId>
             <version>1.8.6</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.tiles</groupId>
+            <artifactId>tiles-template</artifactId>
+            <version>2.2.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tiles</groupId>
+            <artifactId>tiles-velocity</artifactId>
+            <version>2.2.2</version>
+        </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-core</artifactId>
+            <version>1.0.2</version>
+        </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <version>1.0.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.6.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>jcl-over-slf4j</artifactId>
+            <version>1.6.4</version>
+        </dependency>
     </dependencies>
     <build>
         <plugins>
             </plugins>
         </pluginManagement>
     </build>
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>commons-logging</groupId>
+                <artifactId>commons-logging</artifactId>
+                <version>1.1.1</version>
+                <scope>provided</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
 </project>

File src/main/java/com/oudmaijer/administratie/config/SpringConfig.java

View file
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.web.servlet.View;
 import org.springframework.web.servlet.ViewResolver;
 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
 import org.springframework.web.servlet.view.velocity.VelocityViewResolver;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 /**
  *
     public VelocityConfigurer velocityConfig() {
         VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
         velocityConfigurer.setResourceLoaderPath("/WEB-INF/vm/");
+        velocityConfigurer.setConfigLocation(new ClassPathResource("velocity.properties"));
         return velocityConfigurer;
     }
 
         VelocityViewResolver velocityViewResolver = new VelocityViewResolver();
         velocityViewResolver.setCache(false);
         velocityViewResolver.setSuffix(".vm");
+        velocityViewResolver.setToolboxConfigLocation("/WEB-INF/velocity-tools.xml");
         velocityViewResolver.setExposeSpringMacroHelpers(true);
         return velocityViewResolver;
     }
     @Bean
     public ContentNegotiatingViewResolver contentNegotiatingViewResolver() {
         ContentNegotiatingViewResolver contentNegotiatingViewResolver = new ContentNegotiatingViewResolver();
-        contentNegotiatingViewResolver.setOrder(0);
-        Map<String, String> mediaTypes = new HashMap<String, String>();
-        mediaTypes.put("json", "application/json");
-        mediaTypes.put("html", "text/html");
-        mediaTypes.put("xhtml", "application/xhtml+xml");
 
-        contentNegotiatingViewResolver.setMediaTypes(mediaTypes);
         List<ViewResolver> viewResolvers = new ArrayList<ViewResolver>();
-        viewResolvers.add(velocityViewResolver());
         viewResolvers.add(new UrlBasedViewResolver());
+        viewResolvers.add(velocityViewResolver());
 
         List<View> views = new ArrayList<View>();
         views.add(new MappingJacksonJsonView());

File src/main/resources/logback.xml

View file
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <layout class="ch.qos.logback.classic.PatternLayout">
+            <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
+        </layout>
+    </appender>
+
+    <logger name="com.oudmaijer" level="DEBUG"/>
+
+    <root level="debug">
+        <appender-ref ref="STDOUT"/>
+    </root>
+</configuration>

File src/main/resources/velocity.properties

View file
+userdirective=org.apache.tiles.velocity.template.AddAttributeDirective,\
+  org.apache.tiles.velocity.template.AddListAttributeDirective,\
+  org.apache.tiles.velocity.template.DefinitionDirective,\
+  org.apache.tiles.velocity.template.GetAsStringDirective,\
+  org.apache.tiles.velocity.template.ImportAttributeDirective,\
+  org.apache.tiles.velocity.template.InsertAttributeDirective,\
+  org.apache.tiles.velocity.template.InsertDefinitionDirective,\
+  org.apache.tiles.velocity.template.InsertTemplateDirective,\
+  org.apache.tiles.velocity.template.PutAttributeDirective,\
+  org.apache.tiles.velocity.template.PutListAttributeDirective

File src/main/webapp/WEB-INF/velocity-tools.xml

View file
+<?xml version="1.0"?>
+<toolbox>
+</toolbox>