BT

MVC 1.0 JSR Created for Java EE

| by Matt Raible Follow 13 Followers on Sep 17, 2014. Estimated reading time: 3 minutes |

Oracle recently announced a JSR for MVC 1.0. JSR 371 was motivated by results of a Java EE 8 Survey, covered by InfoQ in March of this year. 61% of those surveyed supported the idea of providing support for an action-based MVC framework, alongside JSF. Only 26% felt there was an existing framework that could do the job, and 42% of those mentioned Spring MVC. AngularJS and Play Framework, which play related roles, were commonly mentioned as well.

The MVC 1.0 specification states that web UI frameworks can be categorized as action-based or component-based, and this one falls into the action-based category. It is not a replacement for JSF, it's simply a different approach to building web applications on the Java EE platform. It goes on to say that JAX-RS may be leveraged for the controller, and a new template language is out of scope.

The announcement was met with support from Red Hat, both on the java.net mailing list and in a Java MVC 1.0 blog post. Red Hat engineer and Fellow Bill Burke, voiced his dissent.

The GlassFish Community blog also wrote about MVC 1.0 JSR. They note that the leaders of this JSR have been prominent in the Java EE community: Santiago Pericas-Geertsen (the JAX-RS Specification co-lead) and Manfred Riem (the JSF Specification co-lead).

Ed Burns, the other JSF Specification co-lead, wrote an article "Why another MVC?" to answer some questions. Burns says Jersey MVC will "certainly influence its design" and shows an example of what a controller might look like:

@Path("/")
@Singleton
@Template
@Produces("text/html;qs=5")
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Bookstore {

    private final Map<String>, <Item> items = new TreeMap<String, <Item>();
    private String name;

    public Bookstore() {
        setName("Czech Bookstore");
        getItems().put("1", new Book("Svejk", "Jaroslav Hasek"));
        getItems().put("2", new Book("Krakatit", "Karel Capek"));
        getItems().put("3", new CD("Ma Vlast 1", "Bedrich Smetana", new Track[]{
            new Track("Vysehrad",180),
            new Track("Vltava",172),
            new Track("Sarka",32)}));
    }

    @Path("items/{itemid}/")
    public Item getItem(@PathParam("itemid") String itemid) {
        Item i = getItems().get(itemid);
        if (i == null) {
            throw new NotFoundException(Response
                    .status(Response.Status.NOT_FOUND)
                    .entity("Item, " + itemid + ", is not found")
                    .build());
        }

        return i;
    }

    @GET
    @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
    public Bookstore getXml() {
        return this;
    }

    public long getSystemTime() {
        return System.currentTimeMillis();
    }

    public Map<String>, <Item> getItems() {
        return items;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

Burns writes that this approach will likely be preferred by those who want a great degree of control over the request/response.

Web designers may favor this approach because they view the abstraction provided by a component oriented MVC as just getting in the way when what they really want to do is control the HTML/CSS/JS themselves. Finally, this approach is a great fit for REST because of its tight association with the semantics of HTTP.

Feedback on Reddit was varied. Many don't like the JSR because there will be two web UI frameworks in Java EE. Others mentioned this doesn't seem to be a problem in the Microsoft world (with ASP.NET Webforms and ASP.NET MVC). Redditor johnwaterwood makes an interesting point:

The most ironic thing; I voted for MVC/Action support in the survey thinking it would be about action support in JSF. But they now use my vote as a justification that the community wants Spring MVC to come to Java EE.

Based on the number of Java EE fans critiquing the move and Java web developers praising it, this appears to be a hot topic. Will a MVC 1.0 framework be good enough to sway existing action-oriented enthusiasts to use it? There are a lot of Spring MVC, Grails, Play 2 and Struts 2 fans out there (in that order, according to RebelLabs' Java Tools and Technologies Landscape for 2014). It remains to be seen whether the developers of these frameworks will be compelled to help make MVC 1.0 the best action-oriented web framework for Java developers.

The anticipated schedule for this JSR starts now and ends in two years.

Q3 2014 Expert Group formed
Q1 2015 Early Draft
Q3 2015 Public Review
Q1 2016 Proposed Final Draft
Q3 2016 Final Release

The JSR's project site, https://mvc-spec.java.net, was not yet active when this article was published.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

We need more simplicity by Nykolas de Lima

Burns' controller example looks so much complicated for me. We need to focus on simplicity. CDI came to make our live simpler and we should do the same to this MVC specification.VRaptor framework(www.vraptor.org/en/) is built on top of CDI and I believe that the expert group should be inspired by it.

Redditor johnwaterwood must be a stupid by Pullirajah Rajah

Redditor johnwaterwood must be a stupid, because he/she voted without understanding what he/she voted for! (In the poll it was very clearly asked whether action MVC should be there in parallel with JSF, not as a feature of JSF)

Bill Burke voiced his dissent without mentioning a reason by Pullirajah Rajah

Bill Burke voiced his dissent without mentioning a reason. Can he explain why he does so?

More MVC Frameworks by prathap gym

Please check the below URL

java360.co.in/java-based-mvc-architecture/

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

4 Discuss
BT