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 :-
< .
< .
< .
< .
<
<. 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 :-
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: Basic Portlet to Renderer Navigation using Oracle JPDK