Portlet Development (Spring Edition)¶
Table of Contents
Summary¶
Screen Development (render cycle)
Screen which is displayed on the portlet is created. It can be switched by looking at mode and window status.Screen for the display mode is always necessary.Action Process (processAction cycle)
Data process submitted from the portlet is created. It can be used by setting @ActionMapping annotation to the Controller class method.
It is also possible to make a linkage with other portlet by setting the Event.Event Process (processEvent cycle)
Receive Process of the event generated by other portlet is created. It can be used by setting @EventMapping annotation to the
Controller class method.It will be executed only when Event is set in the Action process.
render mandatory @RenderMapping processAction optional @ActionMapping processEvent optional @EventMapping
Difference from Portlet Development in Spring Portlet MVC Framework¶
portlet.xmlIn the Spring Portlet MVC Framework, <portlet> is added to portlet.xml for each portlet.
However, no individual registration is made in intra-mart Accel Platform.Portlet will be operated based on the <portlet-name>SpringPortlet</portlet-name> setting of WEB-INF/portlet.xml.Value that was set in [URL of Portlet New Registration/Edit Screen] is set to portlet-name. Naming Rule and Location of xml File of context of portletIt is classpath:META-INF/spring/[URL of Portlet New Registration/Edit Screen]-portlet.xml.Please refer to [xml File of portlet context] for detail. JSPPlease be aware that there are some remarks like HEAD tag or BODY tag cannot be used.Please refer to [Remarks when Screen is Created] for detail.
Portlet API¶
it is necessary to utilize the Portlet API.
Especially, for the Action process and Event process to be executed, Portlet API must be used.
You can get Portlet API2.0 document from below.
PortalManager¶
jp.co.intra_mart.foundation.portal.common.PortalManager
Portlet Mode¶
Obtaining Portlet Mode¶
(ex.) PortletMode.VIEW, PortletMode.EDIT
javax.portlet.RenderRequest renderRequest = PortalManager.getRenderRequest(); javax.portletPortletMode portletMode = renderRequest.getPortletMode();
Window Status¶
Obtaining Window Status¶
(ex.) WindowState.NORMAL, WindowState.MAXIMIZED, WindowState.MINIMIZED
javax.portlet.RenderRequest renderRequest = PortalManager.getRenderRequest(); javax.portlet.WindowState windowState = renderRequest.getWindowState();
xml File of portlet context¶
File NameIt should be created in [URL of Portlet New Registration/Edit Screen]-portlet.xml format.(ex.) If you set [welcome] to the URL of Portlet New Registration/Edit Screen, it will be welcome-portlet.xml. Placement LocationIn the module project, please create [META-INF/spring] folder in src/main/resources, and place the xml file.(ex.) src/main/resources/META-INF/spring/welcome-portlet.xml
<context:component-scan base-package="Controller Class Package" />
Screen Development (render cycle)¶
of normal portlet development (portlet-name part of portlet.xml in normal portlet development.)
Controller Class¶
Create the Controller Class which sets @Controller annotation and @RequestMapping annotaion, and
create the method which sets @RenderMapping annotation.Portlet mode (VIEW or EDIT) will be specified in @RequestMapping.Set @RenderMapping annotation to te method which processes render.Please do the setting as @RenderMapping(params = “action=list”), if you want to select the method to process render by the parameter.@Controller @RequestMapping("VIEW") public class ViewController { // default render @RenderMapping public String view() { return "welcome/view.jsp"; } // render that corresponds to renderURL.setParameter("action", "list") @RenderMapping(params = "action=list") public String list() { return "welcome/list.jsp"; } }
JSP File¶
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> <%@ page import="jp.co.intra_mart.foundation.portal.common.PortalManager" %> <%@ page import="javax.portlet.PortletURL" %> <% PortletURL renderURL = PortalManager.createRenderURL(); %> Corresponding to @RenderMapping. <a href="<%=renderURL.toString() %>">default render</a> <br/> <% PortletURL renderURL2 = PortalManager.createRenderURL(); renderURL2.setParameter("action", "list"); %> Corresponding to @RenderMapping(params = "action=list"). <a href="<%=renderURL2.toString() %>">render (action=list)</a> <br/>
RenderRequest, RenderResponse¶
RenderResponse object which are the dedicated objects for displaying portlet.
Obtaining RenderRequest and RenderResponse
RenderRequest renderRequest = PortalManager.getRenderRequest(); RenderResponse renderResponse = PortalManager.getRenderResponse();Obtaining Page Argument in JSP
<% RenderRequest renderRequest = PortalManager.getRenderRequest(); String value = renderRequest.getParameter("param1"); %>Current portlet mode and window status are obtained from RenderRequest.
Scope of RenderRequest¶
portal_cd Key of portal screen where portlet is placed. portalKind Portal type of portal screen where portlet is placed. Following values are obtained.
user User Portal group Group Portal In order to set the request parameters to the portlet, it is necessary to execute Action process or Event process.Request parameters that were once set will be valid during the session duration until the next Action process or Event process is executed.
ActionURL, RenderURL¶
submission to the following URLs would be necessary to communicate with the portlet container.
ActionURL URL to call Action function RenderURL URL to re-display Portal Screen You can obtain them by using PortalManager.
Obtaining ActionURL and RenderURL
PortletURL actionURL = PortalManager.createActionURL(); PortletURL renderURL = PortalManager.createRenderURL();
JSP
<% PortletURL actionURL = PortalManager.createActionURL(); %> <!-- Call service that performs some registration process --> <form action="<%= actionURL.toString() %>" method="POST"> <!-- Value which is used in Registration Process --> <input type="text" name="param1" value=""> <input type="submit" value="Execute"> </form>
Only way to call the Action Process is to submit to ActionURL. Since ActionURL includes portal information, data volume would be large. Please specify POST for method.In case Action Process is called by specifying parameters.<% PortletURL actionURL = PortalManager.createActionURL(); actionURL.setParameter("action", "register") %> <!-- Call service that performs some registration process --> <form action="<%= actionURL.toString() %>" method="POST"> <!-- Value which is used in Registration Process --> <input type="text" name="param1" value=""> <input type="submit" value="Execute"> </form>
You can set parameters by using setParameter, and call Action process.In this case, it will be [action=register].
Action Process (processAction cycle)¶
Controller Class¶
Controller Class which sets @Controller annotation and @RequestMapping annotation is created, and the method which sets
@ActionMapping annotation is created.Portlet mode (VIEW and EDIT) is specified to @RequestMapping.import jp.co.intra_mart.foundation.portal.common.handler.ImEvent; @Controller @RequestMapping("VIEW") public class ViewController { // default render @RenderMapping public String view() { return "welcome/view.jsp"; } // render thaht corresponds to renderURL.setParameter("action", "list") @RenderMapping(params = "action=list") public String list() { return "welcome/list.jsp"; } // default action @ActionMapping public void register(@RequestParam("name") String name, ActionResponse response) { // Registration Process ... // Transition to the render of @RenderMapping(params="action=list") response.setRenderParameter("action", "list"); } // action that corresponds to actionURL.setParameter("action", "publish") // action that generates event @ActionMapping(params = "action=publish") public void publish(ActionRequest request, ActionResponse response) { // Event Generation ImEvent event = new ImEvent(); event.setEvent("hello"); response.setEvent(ImEvent.IM_QNAME, event); } }
JSP File¶
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> <%@ page import="jp.co.intra_mart.foundation.portal.common.PortalManager" %> <%@ page import="javax.portlet.PortletURL" %> <% PortletURL renderURL = PortalManager.createRenderURL(); %> @RenderMapping is supported. <a href="<%=renderURL.toString() %>">default render</a> <br/> <% PortletURL renderURL2 = PortalManager.createRenderURL(); renderURL2.setParameter("action", "list"); %> @RenderMapping(params = "action=list") is supported. <a href="<%=renderURL2.toString() %>">render (action=list)</a> <br/> <% PortletURL actionURL = PortalManager.createActionURL(); %> @ActionMapping is supported. <form method="post" action="<%=actionURL.toString() %>"> <input type="text" name="name" value=""> <button type="submit">Register</button> </form> <br/> <% PortletURL actionURL2 = PortalManager.createActionURL(); actionURL2.setParameter("action", "publish"); %> @ActionMapping(params = "action=publish")is supported. <a href="<%=actionURL2.toString() %>">Event Generation</a> <br/>
ActionRequest, ActionResponse¶
RenderParameter Setting¶
be explicitly set if it is required.
(ex.) RenderParameter setting in processAction cycle
// ActionResponse responose // In case request parameter is set response.setRenderParameter("param1", "value1"); // In case request parameter is deleted response.setRenderParameter("param2", null);(ex.) Use of RenderParameter in render cycle
String value = request.getParamter("param1");
PortletPreferences Setting¶
(ex.) Use of javax.portlet.PortletPreferences
// Obtaining PortletPreferences PortletPreferences preferences = request.getPreferences(); // Obtaining Information which was set in PortletPreferences String value = preferences.getValue("key1", "Default Value"); // Information is set to PortletPreferences. preferences.setValue("key1", "value1"); // PortletPreferences is settled. // Unless this process is done, information is not saved. preferences.store();
Event Setting¶
(ex.) Event Setting in processAction cycle
@ActionMapping(params = "action=publish") public String publish(ActionRequest request, ActionResponse response) { ImEvent event = new ImEvent(); event.setEvent("hello"); response.setEvent(ImEvent.IM_QNAME, event); }
Event Process (processEvent cycle)¶
setting the event by the Action process of any portlet.
In the Event process, setting of RenderParamter, setting of PortletPreferences, and update process such as event setting are made.
Controller Class¶
Controller Class which sets @Controller annotation and @RequestMapping annotation is created, and the method which sets
@EventMapping annotation is created.Portlet Mode (VIEW or EDIT) is specified in @RequestMapping.Please specify @EventMapping(“ImEvent”) and ImEvent to @EventMapping.import jp.co.intra_mart.foundation.portal.common.handler.ImEvent; @Controller @RequestMapping("VIEW") public class AnotherController { // default render @RenderMapping public String view() { return "receive/view.jsp"; } // event @EventMapping("ImEvent") public void event(EventRequest request, EventResponse response) { Event event = request.getEvent(); ImEvent imEvent = (ImEvent) event.getValue(); if (!"hello".equals(imEvent.getEvent())) { // Process is not executed except for the "hello" event. return; } // Some Process ... } }
ImEvent Object¶
Property Name Type Value id String Event ID which has been set in the Action ProcessIf omitted, character string [ImEvent] is set.value String Value of Event which has been set in the Action ProcessIt is obtained as a character string when object is set too.source String Portlet code of portlet which has set the Event.
EventRequest, EventResponse¶
RenderParameter Setting¶
unless any special process is made.
(ex.) Setting of RenderParameter in processEvent cycle
// In case request parameter is set. response.setRenderParameter("param1", "value1"); // In case request parameter is deleted. response.setRenderParameter("param2", null);(ex.) Use of RenderParameter in render cycle
request.getParamter(eventId);
PortletPreferences Setting¶
(ex.) Use of java.portlet.PortletPreferences
// Obtaining PortletPreferences PortletPreferences preferences = request.getPreferences(); // Obtaining Information which was set in PortletPreferences String value = preferences.getValue("key1", "Default Value"); // Set Information to PortletPreferences. preferences.setValue("key1", "value1"); // PortletPreferences is settled. // If this process is not done, information is not stored. preferences.store();
Event Setting¶
However, please be aware that doing the event process within the event process would cause performance degradation, and may possibly cause the event loop.
So, it should be implemented carefully.
(ex.) Event Setting in processEvent cycle
response.setEvent(eventId, eventValue);