Oracle Portal

Thursday, June 21, 2007

Well, I was looking for a simple example of Portlet <--> Renderer in Oracle JPDK. Thanks to Balaji Subramaiam for teaching me this simple code snippet !

I used JDeveloper 10.1.2.0.0 to create my JPDK Portlets and the Renderer Classes.

First, I need to edit my Provider.xml file. I need to ensure that the provider is capable of passing URL Parameters & handling Sessions :-



<. session .>true< /session >
<. passAllUrlParams .>true< /passAllUrlParams >




Next, I need to associate my Renderer class with the Portlet ( JSP ) in this manner :-

<.renderer class="oracle.portal.provider.v2.render.RenderManager">
< .
renderContainer >true< / renderContainer >
< .
renderCustomize >true< / renderCustomize >
< .
autoRedirect >true< / autoRedirect >
< .
contentType >text/html< / contentType >
<
.showPage >/htdocs/testrenderer/TestRenderer.jsp < / showPage >
<. editpage class="com.sandeep.portlet.renderer.TestRenderer">




Now, I need to handle the Navigation. My Portlet (TestRenderer.jsp) uses a simple form in this manner :-

" method="post" action="<%= UrlUtils.htmlFormActionLink(pReq, UrlUtils.DESIGN_LINK) %>">

Next, My Renderer class redirects back to the same page in this manner :-

public class TestRenderer extends BaseManagedRenderer
{
public void renderBody(PortletRenderRequest request) throws PortletException
{
try
{
String strReturnValue = request.getRenderContext().getBackURL();
ProviderSession pSession = request.getSession();
pSession.setAttribute("KEY","BALAJI");
HttpPortletRendererUtil.sendRedirect(request,strReturnValue);
}
catch(IOException ioe)
{
throw new PortletException(ioe);
}
}
}

I have used ProviderSession to check if the Page actually visits the render & returns. Now, back to my TestRenderer.jsp :-

<% PortletRenderRequest pReq = (PortletRenderRequest) request.getAttribute(HttpCommonConstants.PORTLET_RENDER_REQUEST); Object objValue = null; String strName = ""; if (pReq != null) { ProviderSession pSes = pReq.getSession(); objValue = pSes.getAttribute("KEY"); if (objValue != null) { strName = (String)objValue; } pSes.removeAttribute("KEY"); } objValue = null; %>

Well, that't it !!! Thanks, Balaji !!

Now, how does this help me ? Well, I can now call a DAO from the Rendere class, process the result & return to the same Portlet.

Labels: