adam bien's blog

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