Skip to content

Commit

Permalink
Simplified controller
Browse files Browse the repository at this point in the history
Replaced xml-based validation config with annotation
Moved @controller annotation to class level
  • Loading branch information
ivargrimstad committed Apr 21, 2015
1 parent a868101 commit bd69ea5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ target
*.iml
*.swp
.DS_Store

nb-configuration.xml
nbactions.xml
13 changes: 9 additions & 4 deletions src/main/java/de/chkal/todo/web/TodoListController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@
import javax.mvc.Models;
import javax.mvc.validation.ValidationResult;
import javax.validation.Valid;
import javax.ws.rs.*;
import javax.validation.executable.ExecutableType;
import javax.validation.executable.ValidateOnExecution;
import javax.ws.rs.BeanParam;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

/**
* A simple MVC controller.
*/
@Path("/items")
@Controller
public class TodoListController {

@Inject
Expand All @@ -33,7 +40,6 @@ public class TodoListController {
* class to populates the model with all data required by the view.
*/
@GET
@Controller
public String listItems() {
models.put("items", todoService.getItems());
return "items.jsp";
Expand All @@ -47,7 +53,7 @@ public String listItems() {
*/
@POST
@Path("/create")
@Controller
@ValidateOnExecution(type = ExecutableType.NONE)
public String createItem(@BeanParam @Valid CreateItemForm form) {

if (validationResult.isFailed()) {
Expand Down Expand Up @@ -88,7 +94,6 @@ public String createItem(@BeanParam @Valid CreateItemForm form) {
*/
@POST
@Path("/delete")
@Controller
public String deleteItem(@FormParam("id") long id) {

todoService.deleteItem(id);
Expand Down
17 changes: 0 additions & 17 deletions src/main/resources/META-INF/validation.xml

This file was deleted.

0 comments on commit bd69ea5

Please sign in to comment.