diff --git a/pom.xml b/pom.xml index 088665d..f3db6aa 100644 --- a/pom.xml +++ b/pom.xml @@ -69,12 +69,24 @@ spring-webmvc ${org.springframework.version} + + + org.springframework + spring-oxm + ${org.springframework.version} + + junit junit 4.10 - + + javax.validation + validation-api + 1.0.0.GA + + @@ -89,33 +101,9 @@ org.apache.maven.plugins - maven-checkstyle-plugin - 2.9.1 + maven-checkstyle-plugin + 2.9.1 - diff --git a/src/main/java/de/ctdo/bunti/web/RestController.java b/src/main/java/de/ctdo/bunti/web/RestController.java index 37f2907..ed75814 100644 --- a/src/main/java/de/ctdo/bunti/web/RestController.java +++ b/src/main/java/de/ctdo/bunti/web/RestController.java @@ -1,23 +1,23 @@ package de.ctdo.bunti.web; +import javax.validation.Valid; import de.ctdo.bunti.control.BuntiController; -import de.ctdo.bunti.dao.BuntiDevicesDAO; +import de.ctdo.bunti.webmodel.DeviceUpdate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.validation.BindingResult; +import org.springframework.validation.Validator; +import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; @Controller public class RestController { - - private BuntiDevicesDAO devicesDAO; + private Validator validator; private BuntiController controller; @Autowired - public final void setDevicesDAO(BuntiDevicesDAO devicesDAO) { - this.devicesDAO = devicesDAO; + public void setValidator(Validator validator) { + this.validator = validator; } @Autowired @@ -25,20 +25,25 @@ public class RestController { this.controller = controller; } + @RequestMapping(value = "/devices", method = RequestMethod.GET) public final ModelAndView getAll() { - return new ModelAndView("deviceList", "deviceList", devicesDAO.getAllDevices()); + return new ModelAndView("deviceList", "deviceList", controller.getAllDevices()); } @RequestMapping(value = "/devices/{id}", method = RequestMethod.GET) public final ModelAndView getDeviceById(@PathVariable("id") int id) { - return new ModelAndView("device", "device", devicesDAO.getDeviceById(id)); + return new ModelAndView("device", "device", controller.getDeviceById(id)); } @RequestMapping(value = "/devices/{id}", method = RequestMethod.PUT) - public final ModelAndView setDeviceById(@PathVariable("id") int id) { - //controller.setDevice(id, ... ) - return new ModelAndView("device", "device", devicesDAO.getDeviceById(id)); + public String setDeviceById(@ModelAttribute @Valid DeviceUpdate update, BindingResult errors) { + if (errors.hasErrors()) { + return "redirect:/index.html"; + } else { + controller.setDevice(update.getDeviceId(), update.getOptions()); + return "redirect:devices/" + update.getDeviceId(); + } } } diff --git a/src/main/java/de/ctdo/bunti/webmodel/DeviceUpdate.java b/src/main/java/de/ctdo/bunti/webmodel/DeviceUpdate.java new file mode 100644 index 0000000..0bee310 --- /dev/null +++ b/src/main/java/de/ctdo/bunti/webmodel/DeviceUpdate.java @@ -0,0 +1,25 @@ +package de.ctdo.bunti.webmodel; + +import java.io.Serializable; +import java.util.Map; + +public class DeviceUpdate implements Serializable { + private int deviceId; + private Map options; + + public int getDeviceId() { + return deviceId; + } + + public void setDeviceId(int deviceId) { + this.deviceId = deviceId; + } + + public Map getOptions() { + return options; + } + + public void setOptions(Map options) { + this.options = options; + } +} diff --git a/src/main/resources/applicationContext.xml b/src/main/resources/applicationContext.xml new file mode 100644 index 0000000..716be7e --- /dev/null +++ b/src/main/resources/applicationContext.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/marshaller.xml b/src/main/resources/marshaller.xml new file mode 100644 index 0000000..e8bf763 --- /dev/null +++ b/src/main/resources/marshaller.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/dispatcher-servlet.xml b/src/main/webapp/WEB-INF/dispatcher-servlet.xml index 74a44f7..e6e3438 100644 --- a/src/main/webapp/WEB-INF/dispatcher-servlet.xml +++ b/src/main/webapp/WEB-INF/dispatcher-servlet.xml @@ -1,32 +1,32 @@ - - - - - - - - + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> - - - - - - - + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/jsp/device.jsp b/src/main/webapp/WEB-INF/jsp/device.jsp new file mode 100644 index 0000000..3f273e0 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/device.jsp @@ -0,0 +1,24 @@ + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + +<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%> + + + +Device + + +

Device

+ + + + + +
+ +
+ +">Home + + diff --git a/src/main/webapp/WEB-INF/jsp/deviceList.jsp b/src/main/webapp/WEB-INF/jsp/deviceList.jsp new file mode 100644 index 0000000..087e74a --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/deviceList.jsp @@ -0,0 +1,27 @@ + +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + +<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%> + + + +Devices + + +

Devices

+ + + + + + + + + + + +
IdName
+">Home + + diff --git a/src/main/webapp/hello.jsp b/src/main/webapp/WEB-INF/jsp/hello.jsp similarity index 100% rename from src/main/webapp/hello.jsp rename to src/main/webapp/WEB-INF/jsp/hello.jsp diff --git a/src/main/webapp/index.jsp b/src/main/webapp/WEB-INF/jsp/index.jsp similarity index 100% rename from src/main/webapp/index.jsp rename to src/main/webapp/WEB-INF/jsp/index.jsp diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 3829bba..b96981b 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -1,7 +1,6 @@ @@ -12,6 +11,15 @@ CTDO bunti control Server + + org.springframework.web.context.ContextLoaderListener + + + + contextConfigLocation + classpath:applicationContext.xml + + dispatcher