Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MVC 1.0 - Now Even Better!

MVC 1.0 - Now Even Better!

MVC 1.0, as specified by JSR 371, may not be targeted for the upcoming Java EE 8 release, but the specification is still going on as a standalone specification. It is already possible to use the technology in a Java EE 7 environment and as Java EE 8 and 9 evolves, MVC 1.0 will be kept aligned to take advantage of the features provided by the platform.

This session will go through the fundamentals of this specification and explain the core concepts. We will show lots of code samples showing how to use the framework to build MVC 1.0 applications.

There will even be a demo of tooling support available and tips’n’tricks on how to extend the framework. After this session you will have everything you need to get started using the technology to quickly build secure, flexible, localized MVC Web applications.

ivargrimstad

March 08, 2017
Tweet

More Decks by ivargrimstad

Other Decks in Programming

Transcript

  1. @ivar_grimstad
    jDays 2017 - #JSR371
    MVC 1.0 - Now Even Better!
    Ivar Grimstad
    Principal Consultant, Cybercom Sweden

    View Slide

  2. @ivar_grimstad
    jDays 2017 - #JSR371
    @ivar_grimstad
    https://github.com/ivargrimstad
    https://www.linkedin.com/in/ivargrimstad
    http://lanyrd.com/profile/ivargrimstad/

    View Slide

  3. @ivar_grimstad
    jDays 2017 - #JSR371
    JSR 371 Status
    MVC 1.0
    Demo and Samples

    View Slide

  4. @ivar_grimstad
    jDays 2017 - #JSR371
    JSR 371 Status

    View Slide

  5. @ivar_grimstad
    jDays 2017 - #JSR371

    View Slide

  6. @ivar_grimstad
    jDays 2017 - #JSR371

    View Slide

  7. @ivar_grimstad
    jDays 2017 - #JSR371

    View Slide

  8. @ivar_grimstad
    jDays 2017 - #JSR371
    @Controller
    to the Community !

    View Slide

  9. @ivar_grimstad
    jDays 2017 - #JSR371
    January 2017
    Transfer

    Ballot
    August 2014
    First Proposal
    September 2014
    Approved by JCP

    Executive Committee
    September 2014
    Expert Group starts

    discussions
    March 2015
    EDR 1
    October 2016
    October 2015
    EDR 2
    JavaOne
    Past Activities

    View Slide

  10. @ivar_grimstad
    jDays 2017 - #JSR371
    Current Activities
    Transfer approved by the Executive Committee

    Thanks!
    Finalize Transfer

    Oracle Legal is working on the final details
    New Infrastructure Setup

    Started
    Licensing

    Investigating

    View Slide

  11. @ivar_grimstad
    jDays 2017 - #JSR371
    Future Activities
    Formally move infrastructure from java.net 

    Bring in Christian Kaltepoth as co spec-lead

    Revise the Schedule

    Adopt-a-JSR


    View Slide

  12. @ivar_grimstad
    jDays 2017 - #JSR371
    Infrastructure Move

    View Slide

  13. @ivar_grimstad
    jDays 2017 - #JSR371
    Infrastructure Setup Changes
    Code

    java.net -> GitHub (https://github.com/mvc-spec)
    Issue Tracker

    java.net -> GitHub (https://github.com/mvc-spec/mvc-spec/issues)
    Mailing Lists

    java.net -> Google Groups ([email protected])
    Web Site

    java.net -> GitHub Pages (http://www.mvc-spec.org/)

    View Slide

  14. @ivar_grimstad
    jDays 2017 - #JSR371
    Adopt-a-JSR

    View Slide

  15. @ivar_grimstad
    jDays 2017 - #JSR371
    Write Code!
    Blog
    Tweet
    Give us Feedback
    Create a Logotype

    View Slide

  16. @ivar_grimstad
    jDays 2017 - #JSR371
    MVC 1.0 Talks
    DEVNEXUS (http://devnexus.com/)

    Atlanta, USA - February 22-24
    jDays (http://www.jdays.se/)

    Gothenburg, Sweden - Mars 7-8
    JavaLand (https://www.javaland.eu/)

    Brühl, Germany - Mars 28-30
    Developer Week (http://www.developer-week.de/)

    Nürnberg, Germany - June 26-29

    View Slide

  17. @ivar_grimstad
    jDays 2017 - #JSR371
    MVC 1.0

    View Slide

  18. @ivar_grimstad
    jDays 2017 - #JSR371
    Action-based MVC

    View Slide

  19. @ivar_grimstad
    jDays 2017 - #JSR371
    Controller
    Model View
    Request
    Update
    Update

    View Slide

  20. @ivar_grimstad
    jDays 2017 - #JSR371
    Controller
    Model View
    Request
    Update
    Update

    View Slide

  21. @ivar_grimstad
    jDays 2017 - #JSR371
    Controller
    Model View
    Request
    Update
    Update

    View Slide

  22. @ivar_grimstad
    jDays 2017 - #JSR371
    Existing Java EE Technologies

    View Slide

  23. @ivar_grimstad
    jDays 2017 - #JSR371
    Key Decisions

    View Slide

  24. @ivar_grimstad
    jDays 2017 - #JSR371
    Key Decisions

    View Slide

  25. @ivar_grimstad
    jDays 2017 - #JSR371
    Build MVC 1.0 on top of JAX-RS

    View Slide

  26. @ivar_grimstad
    jDays 2017 - #JSR371
    Controllers

    View Slide

  27. @ivar_grimstad
    jDays 2017 - #JSR371
    Controller
    public class HelloController {
    }

    View Slide

  28. @ivar_grimstad
    jDays 2017 - #JSR371
    Controller
    @Path(“hello”)
    public class HelloController {
    }

    View Slide

  29. @ivar_grimstad
    jDays 2017 - #JSR371
    Controller
    @Controller
    @Path(“hello”)
    public class HelloController {
    }

    View Slide

  30. @ivar_grimstad
    jDays 2017 - #JSR371
    Views

    View Slide

  31. @ivar_grimstad
    jDays 2017 - #JSR371
    View
    @Controller
    @Path(“hello”)
    public class HelloController {
    }

    View Slide

  32. @ivar_grimstad
    jDays 2017 - #JSR371
    View
    @Controller
    @Path(“hello”)
    public class HelloController {
    @GET
    public String hello() {
    return “hello.jsp”;
    }
    }

    View Slide

  33. @ivar_grimstad
    jDays 2017 - #JSR371
    View
    @Controller
    @Path(“hello”)
    public class HelloController {
    @GET
    public Viewable hello() {
    return new Viewable(“hello.jsp”);
    }
    }

    View Slide

  34. @ivar_grimstad
    jDays 2017 - #JSR371
    View
    @Controller
    @Path(“hello”)
    public class HelloController {
    @GET
    public Response hello() {
    return Response.status(OK).entity(“hello.jsp”).build();
    }
    }

    View Slide

  35. @ivar_grimstad
    jDays 2017 - #JSR371
    View
    @Controller
    @Path(“hello”)
    public class HelloController {
    @View(“hello.jsp”)
    @GET
    public void hello() {
    }
    }

    View Slide

  36. @ivar_grimstad
    jDays 2017 - #JSR371
    View
    @View(“hello.jsp”)
    @Controller
    @Path(“hello”)
    public class HelloController {
    @GET
    public void hello() {
    }
    }

    View Slide

  37. @ivar_grimstad
    jDays 2017 - #JSR371
    Models

    View Slide

  38. @ivar_grimstad
    jDays 2017 - #JSR371
    Model
    @Named(“greeting”)
    @RequestScoped
    public class Greeting {
    private String message;
    public void setMessage(String message) {
    this.message = message;
    }
    public void getMessage() { return message; }
    }

    View Slide

  39. @ivar_grimstad
    jDays 2017 - #JSR371
    Model
    @View(“hello.jsp”)
    @Controller
    @Path(“hello”)
    public class HelloController {
    @GET
    public void hello() {
    }
    }

    View Slide

  40. @ivar_grimstad
    jDays 2017 - #JSR371
    Model
    @View(“hello.jsp”)
    @Controller
    @Path(“hello”)
    public class HelloController {
    @Inject
    private Greeting greeting;
    @GET
    public void hello() {
    greeting.setMessage(“Hello Atlanta!”);
    }
    }

    View Slide

  41. @ivar_grimstad
    jDays 2017 - #JSR371
    Model
    <%@page contentType=“text/html"
    pageEncoding="UTF-8"%>



    MVC 1.0 Hello Demo


    Hello ${greeting.message}


    View Slide

  42. @ivar_grimstad
    jDays 2017 - #JSR371
    Model
    @View(“hello.jsp”)
    @Controller
    @Path(“hello”)
    public class HelloController {
    @GET
    public void hello() {
    }
    }

    View Slide

  43. @ivar_grimstad
    jDays 2017 - #JSR371
    Model
    @View(“hello.jsp”)
    @Controller
    @Path(“hello”)
    public class HelloController {
    @Inject
    private Models model;
    @GET
    public void hello() {
    model.put(“message”, “Hello Atlanta!”);
    }
    }

    View Slide

  44. @ivar_grimstad
    jDays 2017 - #JSR371
    Model
    <%@page contentType=“text/html"
    pageEncoding="UTF-8"%>



    MVC 1.0 Hello Demo


    Hello ${message}


    View Slide

  45. @ivar_grimstad
    jDays 2017 - #JSR371
    Validation

    View Slide

  46. @ivar_grimstad
    jDays 2017 - #JSR371
    @Controller
    @Path("form")
    public class FormController {
    @POST
    public Response formPost(@Valid @BeanParam FormDataBean f) {
    return Response.status(OK).entity(“data.jsp”).build();
    }
    }
    Validation
    ConstraintValidationException
    @Min, @NotNull
    etc.

    View Slide

  47. @ivar_grimstad
    jDays 2017 - #JSR371
    Validation
    public class FormViolationMapper implements
    ExceptionMapper
    {
    public Response toResponse(ConstraintViolationException e) {
    Set> s= e.getConstraintViolations();
    // process violations ...
    return Response.status(BAD_REQUEST)
    .entity(“error.jsp”).build();
    }
    }

    View Slide

  48. @ivar_grimstad
    jDays 2017 - #JSR371
    @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();
    }
    }
    Validation
    Allows for MVC Error Handling

    View Slide

  49. @ivar_grimstad
    jDays 2017 - #JSR371
    BindingResult

    View Slide

  50. @ivar_grimstad
    jDays 2017 - #JSR371
    View Engines

    View Slide

  51. @ivar_grimstad
    jDays 2017 - #JSR371
    Bring Your Own View Engine

    View Slide

  52. @ivar_grimstad
    jDays 2017 - #JSR371
    ViewEngine
    public interface ViewEngine {
    boolean supports(String view);
    void processView(ViewEngineContext context)
    throws ViewEngineException;
    }

    View Slide

  53. @ivar_grimstad
    jDays 2017 - #JSR371
    View Engine Conflicts
    @Priority(OUTRAGEOSLY_HIGH)

    @ApplicationScoped

    public class FreemarkerViewEngine extends ViewEngineBase {

    }

    View Slide

  54. @ivar_grimstad
    jDays 2017 - #JSR371
    Events

    View Slide

  55. @ivar_grimstad
    jDays 2017 - #JSR371
    Controller
    Model View
    Request
    BeforeControllerEvent
    AfterControllerEvent
    BeforeProcessViewEvent
    AfterProcessViewEvent
    ControllerRedirectEvent

    View Slide

  56. @ivar_grimstad
    jDays 2017 - #JSR371
    Events Example
    @ApplicationScoped
    public class EventObserver {
    void onBeforeController(@Observes BeforeControllerEvent e) {
    println("URI: " + e.getUriInfo().getRequestURI());
    }
    void onAfterController(@Observes AfterControllerEvent e) {
    println("Controller: " +
    e.getResourceInfo().getResourceMethod());
    }
    }

    View Slide

  57. @ivar_grimstad
    jDays 2017 - #JSR371
    Security

    View Slide

  58. @ivar_grimstad
    jDays 2017 - #JSR371
    Cross Site Request Forgery
    @Controller
    @Path(“csrf”)
    public class HelloController {
    @CsrfValid
    @POST
    public Response post(@FormParam(“greeting") String greet {
    }
    }

    View Slide

  59. @ivar_grimstad
    jDays 2017 - #JSR371
    Cross Site Request Forgery
    <%@page contentType=“text/html" pageEncoding="UTF-8"%>



    MVC 1.0 Hello Demo




    value="${mvc.csrf.token}"/>



    View Slide

  60. @ivar_grimstad
    jDays 2017 - #JSR371
    Internationalization

    View Slide

  61. @ivar_grimstad
    jDays 2017 - #JSR371
    Controller
    @Controller
    @Path(“hello”)
    public class HelloController {
    @Inject
    private MvcContext mvc;
    @GET
    public String get() {
    Locale locale = mvc.getLocale();
    }
    }

    View Slide

  62. @ivar_grimstad
    jDays 2017 - #JSR371
    Scopes

    View Slide

  63. @ivar_grimstad
    jDays 2017 - #JSR371
    Model
    ReservationCtl
    Update
    confirmation
    reservation
    OK
    Browser
    POST

    View Slide

  64. @ivar_grimstad
    jDays 2017 - #JSR371
    Model
    ReservationCtl
    Access
    Update
    ConfirmationCtl
    GET
    confirmation
    reservation
    OK
    Redirect
    Browser
    POST

    View Slide

  65. @ivar_grimstad
    jDays 2017 - #JSR371
    Tired of slides?

    View Slide

  66. @ivar_grimstad
    jDays 2017 - #JSR371
    Show me the CODE !

    View Slide

  67. @ivar_grimstad
    jDays 2017 - #JSR371
    Summary

    View Slide

  68. @ivar_grimstad
    jDays 2017 - #JSR371
    Action-based MVC

    View Slide

  69. @ivar_grimstad
    jDays 2017 - #JSR371
    Existing Java EE Technologies

    View Slide

  70. @ivar_grimstad
    jDays 2017 - #JSR371
    Build MVC 1.0 on top of JAX-RS

    View Slide

  71. @ivar_grimstad
    jDays 2017 - #JSR371
    Tool Support

    View Slide

  72. @ivar_grimstad
    jDays 2017 - #JSR371
    JPA Modeler
    jpamodeler.github.io
    Gaurav Gupta
    @jGauravGupta

    View Slide

  73. @ivar_grimstad
    jDays 2017 - #JSR371
    Project Page
    https://www.mvc-spec.org
    GitHub
    https://github.com/mvc-spec
    Reference Implementation
    https://ozark.java.net

    View Slide

  74. @ivar_grimstad
    jDays 2017 - #JSR371
    Samples
    https://github.com/ivargrimstad/mvc-samples
    Blog
    http://www.agilejava.eu/

    View Slide

  75. @ivar_grimstad
    jDays 2017 - #JSR371
    cybercom.com

    View Slide