What Is Portlet Mode
What Is Portlet Mode
A portlet mode indicates the function a portlet is performing in the render method. Normally,
portlets perform different tasks and create different content depending on the function they are
currently performing. A portlet mode advises the portlet what task it should perform and what
content it should generate. When invoking a portlet, the portlet container provides the current
portlet mode to the portlet. Portlets can programmatically change their portlet mode when
processing an action request.
The Portlet Specification defines three portlet modes, VIEW, EDIT, and HELP. The PortletMode
class defines constants for these portlet modes. Every portlet must support VIEW mode and
optionally it can support EDIT and HELP mode
A preference is modified by using setValue. This normally occurs at the personalized layer and
therefore affects only the current user. WebSphere Portal uses two special custom modes from
the set of predefined custom modes in the Java Portlet Specification to allow setting up the more
general preference levels:
The edit_defaults custom portlet mode is used to work directly on the shared
preferences. In this case the personalized preferences level is not available.
Similarly, the config mode is used to read and modify the administrator level of
preferences.
The deployment descriptor level of preferences can only change when the portlet is
redeployed with a modified portlet.xml. It cannot be modified by portlet code.
I built a sample portlet to demonstrate how you can use the edit_defaults and config mode
supported by WebSphere Portal Server.
package com.webspherenotes.portlet.jsr286;
import java.io.IOException;
import java.util.ArrayList;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletPreferences;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
}
PortletMode configMode = new PortletMode("config");
PortletMode editDefaultsMode = new PortletMode("edit_defaults");
protected void doDispatch(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
System.out.println("Entering CustomPortletMode.doDispatch");
System.out.println("Requested portlet mode " + request.getPortletMode());
if(request.getPortletMode().equals(configMode)){
System.out.println("Request for config mode");
doConfig(request, response);
}else if(request.getPortletMode().equals(editDefaultsMode)){
System.out.println("Request for edit_defaults mode");
doEditDefaults(request, response);
}else{
super.doDispatch(request, response);
}
System.out.println("Exiting CustomPortletMode.doDispatch");
}
}
I am defining two custom-portlet-modes here and for both of them the value of portal-
managed equal to true, which is default value to indicate that these custom portlet modes are
managed by WebSphere Portal