Tuesday, 8 October 2013

What is Portlet name Space

Portlet namespace


1.                                namespace is basically a concept which help us in uniquely differentiate among all instance of the same portlet that deployed in portal server its portal container responsibility that it always produce a unique namespace for an instance of a portlet.
2.                                Here I am using instance word its means that if I am using same portlet let say A diployed on two. different page or same page then name space must be different .

3.                                Namespacing ensures that the given name is uniquely associated with this portlet and avoids name conflicts with other elements on the portal page or with other portlets on the page.

Use of Name spaces .

To use it you must import standard portlet library

<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>

This tag produces a unique value for the current portlet:

<portlet:namespace/>

This tag produces a unique value for the current portlet. Namespacing ensures that the given name is uniquely associated with this portlet and avoids name conflicts with other elements on the portal page or with other portlets on the page.

<javasript>
<portlet:namespace/>test()
{

}

</javascript >
<A HREF="javascript:<portlet:namespace/>test()">Encoded name</a>


note you can also use this method to get default name space .

getDefaultNamespace()


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);
}

Very Impotent Links for Java and Portal development development

Jar Download for Spring  Maven Or Gradel Dependency for Spring