sebastiandaschner blog
AsciiBlog on JavaEE MVC (JSR 371)
monday, may 25, 2015The latest version of AsciiBlog now uses the Early Draft Release of the new JavaEE 8 MVC specification (JSR 371). This makes the integration of JSPs with action-based MVC even easier.
The pom.xml was changed to
...
<dependency>
  <groupId>com.oracle.ozark</groupId>
  <artifactId>ozark</artifactId>
  <version>1.0.0-m01</version>
</dependency>
to include Ozark, the RI of MVC.
Ozark relies on Jersey and should to be deployed on a Glassfish (nightly build).
Switching to JSR 371 really simplifies the usage of action-based MVC:
@Controller
public class EntriesController {
    @Inject
    EntriesStore entriesStore;
    @Inject
    Models models;
    @GET
    @Path("{entry}")
    public String getEntry(@PathParam("entry") final String entryName) {
        final Entry entry = entriesStore.getEntry(entryName);
        if (entry == null)
            return "notFound.jsp";
        models.put("entry", entry);
        return "entry.jsp";
    }
}
The EntriesController is returned as a JAX-RS subresource and therefore has no @Path annotation itself.
As MVC is based on JAX-RS many features are included from this specification.
Have a look at the AsciiBlog project on GitHub.
Found the post useful? Subscribe to my newsletter for more free content, tips and tricks on IT & Java: