Copyright© 2008-2022 Sitevision AB, all rights reserved.
public abstract class GenericConfigPortlet extends GenericSiteVisionPortlet
The dispatching of this class ensures that CONFIG mode requests are routed to separate methods (ActionRequest » processConfigAction, RenderRequest » doConfig).
For a basic VIEW portlet that should use the Sitevision custom portlet mode CONFIG, you would typically
extend this class and override the doView
, doConfig
and processConfigAction
methods.
An example!
Below is an example of an implementation of a very simplistic portlet that allows editors to update a portlet preference via the Sitevision custom portlet mode CONFIG:
import senselogic.sitevision.api.portlet.GenericConfigPortlet;
import javax.portlet.*;
import java.io.IOException;
import java.io.PrintWriter;
public class HelloConfigPortlet extends GenericConfigPortlet {
private final static String CITY = "city"; // Name of the preference that can be updated via CONFIG mode
@Override
protected void processConfigAction(ActionRequest anActionRequest, ActionResponse anActionResponse) throws PortletException, IOException {
// GenericConfigPortlet ensures we got here safely, no need to check permissions...
PortletPreferences preferences = anActionRequest.getPreferences();
String newValue = anActionRequest.getParameter(CITY);
if (newValue != null && !newValue.equals(preferences.getValue(CITY, null))) {
preferences.setValue(CITY, newValue);
preferences.store();
}
}
@Override
protected void doConfig(RenderRequest aRenderRequest, RenderResponse aRenderResponse) throws PortletException, IOException {
// GenericConfigPortlet ensures we got here safely, no need to check permissions...
PrintWriter writer = getWriter(aRenderResponse);
String currentValue = aRenderRequest.getPreferences().getValue(CITY, "");
writer.println("<form action=\""+ aRenderResponse.createActionURL() +"\" method=\"post\">");
writer.println(" <label for=\"anIdentifier\" class=\"portlet-form-label\">City:</label>");
writer.println(" <input id=\"anIdentifier\" class=\"portlet-form-input-field\" name=\""+ CITY +"\" value=\""+ currentValue +"\" />");
writer.println(" <input class=\"portlet-form-button\" type=\"submit\" value=\"Save "+ CITY +" preference\" />");
writer.println("</form>");
}
@Override
protected void doView(RenderRequest aRenderRequest, RenderResponse aRenderResponse) throws PortletException, IOException {
PrintWriter writer = getWriter(aRenderResponse);
String currentValue = aRenderRequest.getPreferences().getValue(CITY, "");
writer.println("<p class=\"portlet-class\">Favorite city is "+ currentValue +"</p>");
}
}
Note that the portlet.xml
for the portlet above must specify that it is using the Sitevision custom portlet
mode CONFIG! Below is an excerpt of how:
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app ...>
<portlet>
...
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
<portlet-mode>CONFIG</portlet-mode>
</supports>
...
</portlet>
<custom-portlet-mode>
<description>Sitevision config mode</description>
<portlet-mode>CONFIG</portlet-mode>
</custom-portlet-mode>
</portlet-app>
Modifier and Type | Field and Description |
---|---|
static String |
CONFIG
Name of the Sitevision custom portlet mode CONFIG.
|
Modifier | Constructor and Description |
---|---|
protected |
GenericConfigPortlet()
Does nothing and should not be explicitly called.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
doConfig(RenderRequest aRenderRequest,
RenderResponse aRenderResponse)
Renders the portlet configuration form that should be POST:ed using an
ActionURL . |
protected void |
doDispatch(RenderRequest aRenderRequest,
RenderResponse aRenderResponse)
This method routes the render requests to the proper rendering method.
|
void |
processAction(ActionRequest aActionRequest,
ActionResponse aActionResponse)
Called by the Sitevision portlet container to allow the portlet to process an action request.
|
protected abstract void |
processConfigAction(ActionRequest aActionRequest,
ActionResponse aActionResponse)
This is the "processAction" method for the Sitevision custom portlet mode
CONFIG . |
protected void |
processStandardAction(ActionRequest aActionRequest,
ActionResponse aActionResponse)
This is the "processAction" method for the standard portlet modes (
VIEW , EDIT and HELP ). |
getJcrSession, getUtils, getWriter, getWriter
destroy, doEdit, doHeaders, doHelp, doView, getContainerRuntimeOptions, getDefaultNamespace, getInitParameter, getInitParameterNames, getNextPossiblePortletModes, getPortletConfig, getPortletContext, getPortletName, getProcessingEventQNames, getPublicRenderParameterNames, getPublishingEventQNames, getResourceBundle, getSupportedLocales, getTitle, init, init, processEvent, render, serveResource
public static final String CONFIG
protected GenericConfigPortlet()
A portlet class constructor should only be invoked by the Sitevision portlet container.
Portlet initial state should be implemented via any of the init
methods!
protected final void doDispatch(RenderRequest aRenderRequest, RenderResponse aRenderResponse) throws PortletException, IOException
The standard portlet modes are supported:
PortletMode.VIEW
will be routed to the doView
methodPortletMode.EDIT
will be routed to the doEdit
methodPortletMode.HELP
will be routed to the doHelp
method
This method also supports routing of the Sitevision custom portlet mode CONFIG
.
If the window state of this portlet is WindowState.MINIMIZED
, this method does not route
to any of the rendering methods.
Note! You can not use this class if your portlet should support other portlet modes than the above mentioned. This method is final to ensure that routing/dispatching won't break.
doDispatch
in class GenericPortlet
aRenderRequest
- the render requestaRenderResponse
- the render responsePortletException
- if the portlet cannot fulfill the requestIOException
- if the streaming causes an I/O problempublic final void processAction(ActionRequest aActionRequest, ActionResponse aActionResponse) throws PortletException, IOException
RenderResponse.createActionURL()
method.
This method routes the action requests to the proper rendering method.
The standard portlet modes are supported:
PortletMode.VIEW
will be routed to the
processStandardAction
method
PortletMode.EDIT
will be routed to the
processStandardAction
method
PortletMode.HELP
will be routed to the
processStandardAction
method
This method also supports routing of the Sitevision custom portlet mode CONFIG
.
CONFIG
will be routed to the
processConfigAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
processConfigAction} method
Note! The portlet mode for a CONFIG request will always be re-set to PortletMode.VIEW
when
execution of processConfigAction
has completed (to ensure that VIEW will be used in the subsequent rendering phase).
This method is final to ensure that routing/dispatching won't break.
processAction
in interface Portlet
processAction
in class GenericPortlet
aActionRequest
- the action requestaActionResponse
- the action responsePortletException
- if the portlet cannot fulfill the requestIOException
- if the streaming causes an I/O problemprotected void processStandardAction(ActionRequest aActionRequest, ActionResponse aActionResponse) throws PortletException, IOException
VIEW
, EDIT
and HELP
).
The default implementation does absolutely nothing! Override this method to implement custom behaviour.
aActionRequest
- the action requestaActionResponse
- the action responsePortletException
- if the portlet cannot fulfill the requestIOException
- if the streaming causes an I/O problemprocessAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
protected abstract void processConfigAction(ActionRequest aActionRequest, ActionResponse aActionResponse) throws PortletException, IOException
CONFIG
.
This method will only be executed if requesting user has sufficient rights!
aActionRequest
- the action requestaActionResponse
- the action responsePortletException
- if the portlet cannot fulfill the requestIOException
- if the streaming causes an I/O problemprocessAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
protected abstract void doConfig(RenderRequest aRenderRequest, RenderResponse aRenderResponse) throws PortletException, IOException
ActionURL
.
Invoked in the rendering phase when the portlet is in custom portlet mode CONFIG
.
E.g. when an editor with sufficient rights (write permission on the actual page the portlet instance resides)
double-clicks this portlet in the Sitevision editor.
This method will only be executed if requesting user has sufficient rights!
aRenderRequest
- the render requestaRenderResponse
- the render responsePortletException
- if the portlet cannot fulfill the requestIOException
- if the portlet is unavailable to perform render at this timedoDispatch(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
Sitevision - Portal and Content Management Made Easy
Sitevision is an advanced Java enterprise portal product and a portlet container (JSR 286) that implements Java Content Repository (JSR 283).
Copyright© 2008-2022 Sitevision AB, all rights reserved.