Non portal managed custom portlet modes

Portal vendors may define custom portlet modes for vendor specific functionality for modes that need to be managed by the portal. Portlets may define additional modes that don’t need to be managed by the portal and correspond to the VIEW mode from a portal point of view. The portlet must declare portlet modes that are not managed by the portal via the <portal-managed>false</portal-managed> tag. Portlet modes are considered portal managed by default.

I tried building a sample portlet, to demonstrate if i can use a non container managed portlet mode. My sample portlet has a clipboard mode and in that mode i am just displaying markup that says this clipbarod mode.


<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
<portlet>
<portlet-name>CustomPortletMode</portlet-name>
<display-name>Custom Portlet Mode Portlet</display-name>
<portlet-class>com.webspherenotes.portlet.jsr286.CustomPortletMode</portlet-class>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
<portlet-mode>clipboard</portlet-mode>

</supports>
<portlet-info>
<title>Custom Portlet Mode Portlet</title>
<short-title>Custom Portlet Mode Portlet</short-title>
<keywords>Custom Portlet Mode Portlet</keywords>
</portlet-info>
</portlet>
<custom-portlet-mode>
<description>Sample non portal managed mode</description>
<portlet-mode>clipboard</portlet-mode>
</custom-portlet-mode>

</portlet-app>



This is how my portlet.xml file looks like. I did add one custom-portlet-mode declaration for clipboard with value of portal-managed equal to false indicating that this mode is not managed by portal server.

Then i did create a CustomPortletMode.java like this

package com.webspherenotes.portlet.jsr286;

import java.io.IOException;

import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletURL;
import javax.portlet.RenderMode;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

public class CustomPortletMode extends GenericPortlet{

protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
System.out.println("Entering CustomPortletMode.doView()");
response.setContentType("text/html");
response.getWriter().println("Hello from View Mode");
/* PortletURL porteltURL = response.createRenderURL();
porteltURL.setPortletMode(new PortletMode("clipboard"));
response.getWriter().println("<a href='"+ porteltURL.toString()+"'>Go to clipboard Mode</a>"); */
System.out.println("Exiting CustomPortletMode.doView()");
}


protected void doClipboard(RenderRequest request, RenderResponse response)
throws PortletException, IOException{
System.out.println("Entering CustomPortletMode.doClipboard()");
response.setContentType("text/html");
response.getWriter().println("Hello from Clipboard Mode");
System.out.println("Exiting CustomPortletMode.doClipboard()");

}


PortletMode clipboardMode = new PortletMode("clipboard");
protected void doDispatch(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
System.out.println("Entering CustomPortletMode.doDispatch");
System.out.println("Portlet Mode " + request.getPortletMode());
System.out.println("Is Config mode " + request.getPortletMode().equals(configMode));
System.out.println("Is Config mode " + request.getPortletMode().equals(clipboardMode));
if(request.getPortletMode().equals(clipboardMode)){
doClipboard(request, response);
}else{
super.doDispatch(request, response);
}
System.out.println("Exiting CustomPortletMode.doDispatch");
}

}


When i tried deploying this portlet in the WebSPhere Portal Server it did not show me a button to switch to Clipboard mode. I tried creating a link in the VIEW mode manually that will give me change to move to clipboard mode. But when i deployed in WPS the doView() started failing with this exception. It seems that WPS does not like concept of non portal managed custom mode.

If you want to use a Custom POrtlet mode in your portlet, then you will have to override the doDispatch() method of the GenericPortlet class and in that method check if the request is for custom portlet mode and if yes forward control to the appropriate method to handle that mode, if you dont do that GenericPortlet will throw exception



javax.portlet.PortletModeException: Can't set this PortletMode
at com.ibm.ws.portletcontainer.core.impl.PortletURLImpl.setPortletMode(PortletURLImpl.java:74)
at com.webspherenotes.portlet.jsr286.CustomPortletMode.doView(CustomPortletMode.java:20)
at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:328)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
at com.ibm.ws.portletcontainer.invoker.impl.PortletFilterChainImpl.doFilter(PortletFilterChainImpl.java:128)
at com.ibm.wps.propertybroker.standard.filter.C2APortletFilter.doFilter(C2APortletFilter.java:183)
at com.ibm.ws.portletcontainer.invoker.impl.PortletFilterChainImpl.doFilter(PortletFilterChainImpl.java:120)
at com.ibm.ws.portletcontainer.invoker.impl.PortletServlet.doDispatch(PortletServlet.java:573)
at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:114)
at com.ibm.isclite.container.collaborator.PortletServletCollaborator.doRender(PortletServletCollaborator.java:68)
at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:105)
at com.ibm.ws.portletcontainer.rrd.RRDServerPortletServletCollaborator.doRender(RRDServerPortletServletCollaborator.java:123)
at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:105)
at com.ibm.ws.portletcontainer.cache.CacheCollaborator.doRender(CacheCollaborator.java:92)
at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:105)
at com.ibm.wps.pe.pc.waspc.core.impl.PortletServletCollaboratorImpl.doRender(PortletServletCollaboratorImpl.java:156)
at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:105)
at com.ibm.ws.portletcontainer.invoker.impl.PortletServlet.doDispatch(PortletServlet.java:273)
at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:82)
at com.ibm.isclite.container.collaborator.PortletServletCollaborator.doDispatch(PortletServletCollaborator.java:124)
at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:74)
at com.ibm.ws.portletcontainer.rrd.RRDServerPortletServletCollaborator.doDispatch(RRDServerPortletServletCollaborator.java:60)
at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:74)
at com.ibm.ws.portletcontainer.cache.CacheCollaborator.doDispatch(CacheCollaborator.java:74)
at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:74)
at com.ibm.wps.pe.pc.waspc.core.impl.PortletServletCollaboratorImpl.doDispatch(PortletServletCollaboratorImpl.java:121)
at com.ibm.ws.portletcontainer.invoker.impl.PortletServletCollaboratorChainImpl.doCollaborator(PortletServletCollaboratorChainImpl.java:74)
at com.ibm.ws.portletcontainer.invoker.impl.PortletServlet.dispatch(PortletServlet.java:208)
at com.ibm.ws.portletcontainer.invoker.impl.PortletServlet.service(PortletServlet.java:165)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1146)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1087)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:118)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:837)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:680)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:588)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:524)
at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:122)
at com.ibm.ws.portletcontainer.webextension.PortletExtensionProcessor.handleRequest(PortletExtensionProcessor.java:93)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.include(WebAppRequestDispatcher.java:639)
at com.ibm.ws.portletcontainer.invoker.impl.PortletInvokerImpl.invoke(PortletInvokerImpl.java:235)
at com.ibm.ws.portletcontainer.invoker.impl.PortletInvokerCollaboratorChainImpl.doCollaborator(PortletInvokerCollaboratorChainImpl.java:78)
at com.ibm.ws.portletcontainer.cache.PortletInvokerCacheCollaborator.doRender(PortletInvokerCacheCollaborator.java:58)
at com.ibm.ws.portletcontainer.invoker.impl.PortletInvokerCollaboratorChainImpl.doCollaborator(PortletInvokerCollaboratorChainImpl.java:67)
at com.ibm.ws.portletcontainer.ext.PortletInvokerPerformanceCollaborator.invoke(PortletInvokerPerformanceCollaborator.java:313)
at com.ibm.ws.portletcontainer.ext.PortletInvokerPerformanceCollaborator.doInvoke(PortletInvokerPerformanceCollaborator.java:101)
at com.ibm.ws.portletcontainer.ext.PortletInvokerPerformanceCollaborator.invokePMI(PortletInvokerPerformanceCollaborator.java:163)
at com.ibm.ws.portletcontainer.ext.PortletInvokerPerformanceCollaborator.doInvoke(PortletInvokerPerformanceCollaborator.java:91)
at com.ibm.ws.portletcontainer.ext.PortletInvokerPerformanceCollaborator.doRender(PortletInvokerPerformanceCollaborator.java:74)
at com.ibm.ws.portletcontainer.invoker.impl.PortletInvokerCollaboratorChainImpl.doCollaborator(PortletInvokerCollaboratorChainImpl.java:67)
at com.ibm.ws.portletcontainer.invoker.impl.PortletInvokerImpl.render(PortletInvokerImpl.java:97)
at com.ibm.ws.portletcontainer.PortletContainerImpl.doRender(PortletContainerImpl.java:119)


When i deployed same code in the Apache Pluto i could go to Clipboard button like this

1 comment: