Controller
Model View
Request
Update
Update
Get
Component-based MVC
Slide 12
Slide 12 text
Controller
Model View
Request
Update
Update
Get
Action-based MVC
Slide 13
Slide 13 text
Comparable Frameworks
Spring MVC
around since 2005
“Real World” since 2008 (Spring 2.5 onward)
today’s leader in Action-Land
Struts 2
around since 2004 (WebWork 2)
“Real World” since 2007 (Struts 2.0.9 onward)
still widely adopted
Slide 14
Slide 14 text
Existing Java EE
Technologies
Slide 15
Slide 15 text
Key Decisions
Slide 16
Slide 16 text
Key Decisions
Slide 17
Slide 17 text
Build MVC 1.0 on top of
JAX-RS
Slide 18
Slide 18 text
Controllers
Slide 19
Slide 19 text
public class HelloController {
}
Controller
Slide 20
Slide 20 text
@Path(“hello”)
public class HelloController {
}
Controller
Slide 21
Slide 21 text
@Controller
@Path(“hello”)
public class HelloController {
}
Controller
Slide 22
Slide 22 text
Views
Slide 23
Slide 23 text
@Controller
@Path(“hello”)
public class HelloController {
}
View
Slide 24
Slide 24 text
@Controller
@Path(“hello”)
public class HelloController {
@GET
public String hello() {
return “hello.jsp”;
}
}
View
Slide 25
Slide 25 text
@Controller
@Path(“hello”)
public class HelloController {
@GET
public Viewable hello() {
return new Viewable(“hello.jsp”);
}
}
View
Slide 26
Slide 26 text
@Controller
@Path(“hello”)
public class HelloController {
@GET
public Response hello() {
return Response.status(OK).entity(“hello.jsp”).build();
}
}
View
Slide 27
Slide 27 text
@Controller
@Path(“hello”)
public class HelloController {
@View(“hello.jsp”)
@GET
public void hello() {
}
}
View
Slide 28
Slide 28 text
@View(“hello.jsp”)
@Controller
@Path(“hello”)
public class HelloController {
@GET
public void hello() {
}
}
View
Slide 29
Slide 29 text
Models
Slide 30
Slide 30 text
@Named(“greeting”)
@RequestScoped
public class Greeting {
private String message;
public void setMessage(String message) {
this.message = message;
}
public void getMessage() { return message; }
}
Model
Slide 31
Slide 31 text
@View(“hello.jsp”)
@Controller
@Path(“hello”)
public class HelloController {
@GET
public void hello() {
}
}
Model
Slide 32
Slide 32 text
@View(“hello.jsp”)
@Controller
@Path(“hello”)
public class HelloController {
@Inject
private Greeting greeting;
@GET
public void hello() {
greeting.setMessage(“Hello GIDS 2016!”);
}
}
Model
@Controller
@Path("form")
public class FormController {
@POST
public Response formPost(@Valid @BeanParam FormDataBean f) {
return Response.status(OK).entity(“data.jsp”).build();
}
}
ConstraintValidationException
@Min, @NotNull
etc.
Validation
Slide 39
Slide 39 text
public class FormViolationMapper implements
ExceptionMapper
{
public Response toResponse(ConstraintViolationException e) {
// process violations …
return Response.status(BAD_REQUEST)
.entity(“error.jsp”).build();
}
}
Validation
Slide 40
Slide 40 text
@Controller
@Path("form")
public class FormController {
@Inject private BindingResult br;
@POST
public Response formPost(@Valid @BeanParam FormDataBean f) {
if (br.isFailed()) {
return Response.status(BAD_REQUEST)
.entity(“error.jsp”).build();
}
return Response.status(OK).entity(“data.jsp”).build();
}
}
Allows for MVC Error Handling
Validation
Slide 41
Slide 41 text
Security
Slide 42
Slide 42 text
@Controller
@Path(“csrf”)
public class HelloController {
@CsrfValid
@POST
public Response post(@FormParam(“greeting") String greet {
}
}
Cross Site Request Forgery