Commits

Stephan Oudmaijer  committed dc6f28d

Added html5 history api.
Added Tiles2

  • Participants
  • Parent commits 63a18fe

Comments (0)

Files changed (7)

         </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
+            <artifactId>spring-oxm</artifactId>
+            <version>${spring.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
             <artifactId>spring-context</artifactId>
             <version>${spring.version}</version>
         </dependency>
             <version>${spring.version}</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.tiles</groupId>
+            <artifactId>tiles-jsp</artifactId>
+            <version>2.2.2</version>
+        </dependency>
+        <dependency>
             <groupId>cglib</groupId>
             <artifactId>cglib-nodep</artifactId>
             <version>2.2</version>

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

 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
 import org.springframework.web.servlet.view.ContentNegotiatingViewResolver;
-import org.springframework.web.servlet.view.InternalResourceViewResolver;
-import org.springframework.web.servlet.view.JstlView;
+import org.springframework.web.servlet.view.UrlBasedViewResolver;
 import org.springframework.web.servlet.view.json.MappingJacksonJsonView;
+import org.springframework.web.servlet.view.tiles2.TilesConfigurer;
+import org.springframework.web.servlet.view.tiles2.TilesView;
 import org.springframework.web.servlet.view.xml.MarshallingView;
 
 import java.util.ArrayList;
  *
  */
 @Configuration
-@ComponentScan("com.oudmaijer.administratie")
+@ComponentScan("com.oudmaijer.administratie.web")
 @EnableWebMvc
 public class DispatcherConfig extends WebMvcConfigurerAdapter {
 
-    public InternalResourceViewResolver internalResourceViewResolver() {
-        InternalResourceViewResolver ur = new InternalResourceViewResolver();
-        ur.setViewClass(JstlView.class);
-        ur.setPrefix("/WEB-INF/view/");
-        ur.setSuffix(".jsp");
-        return ur;
+    @Bean
+    public TilesConfigurer tilesConfigurer() {
+        TilesConfigurer tc = new TilesConfigurer();
+        tc.setDefinitions(new String[] {"WEB-INF/tiles-definitions.xml"});
+        return tc;
+    }
+
+    public UrlBasedViewResolver tilesViewResolver() {
+        UrlBasedViewResolver tvr = new UrlBasedViewResolver();
+        tvr.setViewClass(TilesView.class);
+        return tvr;
     }
 
     @Override
         contentNegotiatingViewResolver.setMediaTypes(mediaTypes);
 
         List<ViewResolver> vr = new ArrayList<ViewResolver>();
-        vr.add(internalResourceViewResolver());
+        vr.add(tilesViewResolver());
         contentNegotiatingViewResolver.setViewResolvers(vr);
 
         List<View> views = new ArrayList<View>();
         views.add(new MappingJacksonJsonView());
         views.add(new MarshallingView());
+        contentNegotiatingViewResolver.setFavorPathExtension(true);
         contentNegotiatingViewResolver.setDefaultViews(views);
         contentNegotiatingViewResolver.setDefaultContentType(MediaType.TEXT_HTML);
 

File src/main/java/com/oudmaijer/administratie/web/InvoiceController.java

 
 import com.oudmaijer.administratie.core.domain.invoice.Invoice;
 import com.oudmaijer.administratie.core.service.InvoiceService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.validation.BindingResult;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 
 import javax.inject.Inject;
 import javax.validation.Valid;
-import java.util.Collection;
-import java.util.List;
 
 @Controller
 @RequestMapping("/invoice")
     }
 
     @RequestMapping(value = "/add", method = RequestMethod.PUT)
-    @ResponseStatus(HttpStatus.CREATED)
     public String addInvoice(@Valid Invoice invoice, BindingResult errors, RedirectAttributes redirectAttributes) {
         if(errors.hasErrors()) {
             return "invoice/new";
         }
         invoiceService.addInvoice(invoice);
         redirectAttributes.addFlashAttribute("success", "true");
-        return "redirect:list";
+        return "redirect:/app/invoice/list";
     }
 
     @RequestMapping(value = "/list", method = RequestMethod.GET)

File src/main/java/com/oudmaijer/administratie/web/SimplePageController.java

 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 
-/**
- * Created by IntelliJ IDEA.
- * User: Stephan
- * Date: 9-5-12
- * Time: 21:51
- * To change this template use File | Settings | File Templates.
- */
 @Controller
 public class SimplePageController {
 

File src/main/webapp/WEB-INF/tiles-definitions.xml

+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE tiles-definitions PUBLIC
+        "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
+        "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
+<tiles-definitions>
+    <definition name="template" template="/WEB-INF/view/template/template.jsp">
+    </definition>
+    <definition name="home" extends="template">
+        <put-attribute name="content" value="/WEB-INF/view/home.jsp"/>
+    </definition>
+    <definition name="invoice/list" extends="template">
+        <put-attribute name="content" value="/WEB-INF/view/invoice/list.jsp"/>
+    </definition>
+    <definition name="invoice/new" extends="template">
+        <put-attribute name="content" value="/WEB-INF/view/invoice/new.jsp"/>
+    </definition>
+    <definition name="invoice/details" extends="template">
+        <put-attribute name="content" value="/WEB-INF/view/invoice/details.jsp"/>
+    </definition>
+</tiles-definitions>

File src/main/webapp/WEB-INF/view/invoice/new.jsp

 
 Nieuwe factuur
 
-<form:form modelAttribute="invoice" action="/app/invoice/add" method="put">
+<form:form modelAttribute="invoice" action="add" method="put">
     <p><form:errors path="*"/></p>
     <p>Opmerking: <form:input path="comment" type="text" name="comment"/></p>
     <input type="submit"/>

File src/main/webapp/WEB-INF/view/template/template.jsp

+<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
+<html>
+<head>
+    <!-- jQuery -->
+    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
+
+    <!-- jQuery ScrollTo Plugin -->
+    <script defer src="http://balupton.github.com/jquery-scrollto/scripts/jquery.scrollto.min.js"></script>
+
+    <!-- History.js -->
+    <script defer src="http://balupton.github.com/history.js/scripts/bundled/html4+html5/jquery.history.js"></script>
+
+    <!-- This Gist -->
+    <script defer src="http://gist.github.com/raw/854622/ajaxify-html5.js"></script>
+</head>
+<body>
+    <h2>Bladiebla</h2>
+    <tiles:insertAttribute name="content" />
+</body>
+</html>