Friday 4 October 2013

How Create Custom Mode in Portlets

How Create Custom Mode in Portlets


Step :01 → First of all you need to configure mode  in your portlet.xml file


<custom-portlet-mode>
<portlet-mode>custommode</portlet-mode>
</custom-portlet-mode>


Step :02 →Instantiate with in your Portlet  by passing  mode name in PortletMode class and make this variable as final .


private static final PortletMode CUSTOM_MODE = new PortletMode("custommode");


Step :03 → Define the Method that you want to Execute  for this Mode


protected void doCustomMode(RenderRequest request, RenderResponse response) throws PortletException, IOException {
// Set the MIME type for the render response
response.setContentType(request.getResponseContentType());


// Invoke the JSP to render
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(getJspFilePath(request, CONFIG_JSP));
rd.include(request,response);
}
 


Step:04 -->Overrides the doDispacher method of the GenericPortlet


/**
* Override doDispatch method for handling custom portlet modes.
*
* @see javax.portlet.GenericPortlet#doDispatch(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
*/
protected void doDispatch(RenderRequest request, RenderResponse response) throws PortletException, IOException {
if (!WindowState.MINIMIZED.equals(request.getWindowState())){
PortletMode mode = request.getPortletMode();
if (CUSTOM_MODE.equals(mode)) {
doCustomMode(request, response);
return;
}
}
super.doDispatch(request, response);
}

No comments:

Post a Comment

Very Impotent Links for Java and Portal development development

Jar Download for Spring  Maven Or Gradel Dependency for Spring