Writing Custom Portlet Mode in WebSphere Portal



Steps
a.  Override generic portlet Dispatch method

private static final PortletMode CUSTOM_CONFIG_MODE = new PortletMode("config");
private static final PortletMode CUSTOM_EDIT_DEFAULTS_MODE = new PortletMode("edit_defaults");

protected void doDispatch(RenderRequest request, RenderResponse response) throws PortletException, IOException {
              if (!WindowState.MINIMIZED.equals(request.getWindowState())){
                     PortletMode mode = request.getPortletMode();                 
                     if (CUSTOM_CONFIG_MODE.equals(mode)) {
                           doCustomConfigure(request, response);
                           return;
                     }
                     else if (CUSTOM_EDIT_DEFAULTS_MODE.equals(mode)) {
                           doCustomEditDefaults(request, response);
                           return;
                     }
              }
              super.doDispatch(request, response);
       }

b. Add following in the portlet.xml

<custom-portlet-mode>
            <portlet-mode>config</portlet-mode>
      </custom-portlet-mode>
      <custom-portlet-mode>
            <portlet-mode>edit_defaults</portlet-mode>
</custom-portlet-mode>

Add following entries under the portlet tag
<supports>
      <portlet-mode>config</portlet-mode>
      <portlet-mode>edit_defaults</portlet-mode>
</supports>

Note: If a custom portlet mode defined in the deployment descriptor is not mapped to a custom portlet mode provided by WebSphere Portal, portlets must not be invoked in that portlet mode.  Ex: you can not create like "resize" mode for the portlet that deployed in websphere as websphere doesn't support it.

No comments:

Post a Comment