PortletMVC4Spring is a way to develop portlets using the Spring Framework and the Model View Controller (MVC) pattern. While the Spring Framework supports developing servlet-based web applications using Spring Web MVC, PortletMVC4Spring supports developing portlet-based applications using MVC. You can build Spring Framework Liferay DXP portlets with features like these:
- Inversion of control (IoC) / dependency injection (DI)
- Annotations
- Security
- Binding and validation
- Multi-part file upload
- … and more
You’ll learn these things about PortletMVC4Spring:
-
Developing a Portlet Using PortletMVC4Spring: Demonstrates creating and deploying a portlet using PortletMVC4Spring.
-
Annotation-based Controller Development: Shows how to implement controllers using plain old Java objects (POJOs) and annotations.
If you’re familiar with Spring Web MVC, it’s helpful to compare it with
PortletMVC4Spring. Portlet workflow differs from servlet workflow because
a request to the portlet can have two distinct phases: the ACTION_PHASE
and
the RENDER_PHASE
. The ACTION_PHASE
is executed only once and is where any
back-end changes or actions occur, such as making changes in a database. The
RENDER_PHASE
presents the portlet’s content to the user each time the display
is refreshed. Thus for a single request, the ACTION_PHASE
is executed only
once, but the RENDER_PHASE
may be executed multiple times. This provides (and
requires) a clean separation between the activities that modify the system’s
persistent state and the activities that generate content. The Portlet 2.0
Specification added two more phases: The event phase and the resource phase,
both of which are supported by annotation-driven dispatching.
PortletMVC4Spring provides annotations that support requests from the render,
action, event, and resource serving portlet phases; Spring Web MVC provides only
a @RequestMapping
annotation. Where a Spring Web MVC controller might have
a single handler method annotated with @RequestMapping
, an equivalent
PortletMVC4Spring controller might have multiple handler methods, each using
one of the phase annotations: @ActionMapping
, @EventMapping
,
@RenderMapping
, or @ResourceMapping
.
The PortletMVC4Spring framework uses a DispatcherPortlet
that dispatches
requests to handlers, with configurable handler mappings and view resolution,
just as the DispatcherServlet
in the web framework does.
Liferay also provides full-featured sample portlets that demonstrate using JSP and Thymeleaf view templates. They exercise many features that form-based portlet applications typically require.
The samples are available here:
Now that you have a basic understanding of PortletMVC4Spring portlets and how they compare to Spring Web MVC applications, it’s time to develop a PortletMVC4Spring portlet.