Adam Bien's Weblog

Java EE 8 MVC (JSR-371) Example

Java EE 8 comes with a lean Model View Controller (MVC) specification for action based web frameworks JSR-371. The PDF document is 33 pages lean and pragmatic.

Project ozark.java.net is the reference implementation and it already works well on GlassFish 4.1 daily build.

To get a feeling for the spec I implemented a simplistic example based on the ECB idea:


package com.airhacks.time.presentation;

import com.airhacks.time.business.clock.boundary.AtomClock;
import com.oracle.ozark.core.Models;
import javax.inject.Inject;
import javax.mvc.Controller;
import javax.ws.rs.GET;
import javax.ws.rs.Path;


@Controller
@Path("time")
public class TimeController {

    @Inject
    Models models;

    @Inject
    AtomClock clock;

    @GET
    public String now() {
        this.models.put("time", new Time(clock.currentTime()));
        return "/time.jsp";
    }

}

The whole project with WAR and sources was pushed to github.com/AdamBien/javaee8-mvc-sample/

I also introduced the MVC sample in the 14th airhacks Q&A broadcast

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting


NEW workshop: HTML 5 and JavaScript Essentials, Three days in April 2017: from Java EE 7 Architectures over Microservices to Performance, Troubleshooting and Monitoring
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

Comments:

I think the most important thing distinguishing JAX-RS from MVC-JSR is possibility to use a session, right? Is it already possible?

Posted by PeterW on May 06, 2015 at 08:55 PM CEST #

Really ? Ten years ago with Spring I writed the same code, isn't a big innovation this mvc jsr in the 2015

Posted by Ciccio on May 07, 2015 at 04:53 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
realworldpatterns.com
Online Workshops
...the last 150 posts
...the last 10 comments
License