MVCBean Portlets

***NEW*** in Apache Pluto 3.1.0: A large subset of the JSR 371 (MVC 1.0) Specification has been implemented which enables "MVCBean" portlet development. This feature is an open source proof-of-concept that could possibly serve as the basis for the next version of the Portlet Specification (3.1).

MVC 1.0

Portlet 3.0 introduced the concept of a CDI "bean portlet" featuring annotation-driven method dispatching with annotations such as @ActionMethod, @RenderMethod, and @ServeResourceMethod. This is effectively the "C" (Controller) concern of the Model/View/Controller (MVC) design pattern.

However, Portlet 3.0 did not provide the "M" (Model) or "V" (View) concerns, nor did it provide a CDI scope that allows for model data to survive from the ACTION_PHASE to the RENDER_PHASE of the portlet lifecycle.

In order to remedy this, Pluto implements MVC 1.0 in a way that makes sense for portlet development. Most of the requirements of MVC 1.0 are implemented; the main exception being those requirements that depend on JAX-RS for controller method dispatching. In other words, rather than using @GET and @POST from JAX-RS, MVCBean portlets rely on the aforementioned Portlet 3.0 annotations for controller method dispatching. Finally, Pluto implements MVC 1.0 @RedirectScoped so that model data can survive from the ACTION_PHASE to the RENDER_PHASE of the portlet lifecycle.

Consider the following MVC servlet/webapp based example which uses the JAX-RS @Path and @GET annotations for method dispatching. These JAX-RS annotations simply don't map well to the opaque nature of PortletURLs or the portlet lifecycle:

@Path("hello")
public class HelloController {

    @Inject
    private Models models;

    @GET
    @Controller
    public String hello() {
	   models.put("user", new User());
	   return "hello.jspx";
    }
}

Instead, with Pluto's implementation of MVC 1.0, Portlet 3.0 annotations are used for controller method dispatching:

@PortletRequestScoped
public class HelloController {

    @Inject
    private Models models;

    @RenderMethod(portletNames = {"portlet1"})
    @Controller
    public String hello(RenderRequest renderRequest, RenderResponse renderResponse) {
	   models.put("user", new User());
	   return "hello.jspx";
    }
}

Java™ EE / Jakarta EE Programming Model

Since the MVCBean feature is built on JCP standards like MVC, CDI, and Bean Validation, MVCBean portlet development relies on the familiar Java™ EE / Jakarta EE programming model.

Supported MVC View Engines

Pluto supports the following file extensions for views:

  • .jsp/.jspx via Pluto's JSP view engine
  • .html via Pluto's Thymeleaf view engine (requires the Thymeleaf templating engine as a dependency)

Demo Portlets

The Pluto project contains real-world MVCBean demo portlets that demonstrate features that are typically found in web applications:

  • HTML form-based submission
  • XSS protection via MVC's Encoders API
  • CSRF protection via MVC's @CsrfProtected annotation
  • Injection of @RedirectScoped model data via MVC's Models API
  • Navigation between views via methods annotated with MVC's @Controller annotation
  • Input validation via Bean Validation and Hibernate Validator
  • Uploading attachments via Portlet 3.0 multipart file upload

Demo #1: "Job Applicant" portlet featuring JSPX views

Demo #2: "Job Applicant" portlet featuring Thymeleaf views

Maven Archetypes

Refer to the Maven Archetypes page in order to learn how to quickly generate a new MVCBean portlet project from a starter template.