« Back

JSR 286 new features(1 in 5)--PUBLIC RENDER PARAMETER

Company Blogs December 8, 2008 By Jian Cao Staff

This is a simple series of articles to indicate the new features of Jsr 286

 

1.Public Render Paramter

Here we simulate a Sender and a Receiver to show this

portlet.xml(Define the public render paramter and declare the portlets which support the public paramter)

  -------------------------------------------------------------------

  <portlet>
        <portlet-name>Publisher</portlet-name>
        <portlet-class>
            com.liferay.portlet.test.Sender
        </portlet-class>
        <portlet-info>
            <title>Publisher
            </title>
            <short-title>Publisher
            </short-title>
        </portlet-info>
        <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>VIEW</portlet-mode>
        </supports>
        <supported-public-render-parameter>
            public-render-param
        </supported-public-render-parameter>

        <supported-locale>en</supported-locale>
    </portlet>

    <portlet>
        <portlet-name>Receiver
        </portlet-name>
        <portlet-class>
            com.liferay.portlet.test.Receiver

        </portlet-class>
        <portlet-info>
            <title> Receiver
            </title>
            <short-title> Receiver
            </short-title>
        </portlet-info>
        <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>VIEW</portlet-mode>
        </supports>
        <supported-public-render-parameter>
            public-render-param
        </supported-public-render-parameter>

        <supported-locale>en</supported-locale>
    </portlet>
<!----Define the parameter--->
    <public-render-parameter>
        <identifier>public-render-param</identifier>
        <qname xmlns:x="http://www.liferay.com/public-render-parameters">x:public-render-param</qname>
    </public-render-parameter>

Sender.java

 

public class Sender implements Portlet {

 . . . . . .

    public void processAction(ActionRequest actionRequest,

            ActionResponse actionResponse) throws PortletException, IOException {

        String publicRenderParamValue = actionRequest.getParameter("public-render-param");

        actionResponse.setRenderParameter("public-render-param", publicRenderParamValue);

    }

    public void render(RenderRequest renderRequest,

           RenderResponse renderResponse) throws PortletException, IOException {

       PortletRequestDispatcher portletRequestDispatcher = portletConfig

              .getPortletContext().getRequestDispatcher(

                     "/WEB-INF/jsp/view.jsp");

       portletRequestDispatcher.include(renderRequest, renderResponse);

    }

. . . . .

}

 

Receiver.java

public class Sender implements Portlet {

. . . . .

    public void render(RenderRequest renderRequest,

            RenderResponse renderResponse) throws PortletException, IOException {

        PortletRequestDispatcher portletRequestDispatcher = portletConfig

                .getPortletContext()

                .getRequestDispatcher(

                        "/WEB-INF/jsp/showParameter.jsp");

        portletRequestDispatcher.include(renderRequest, renderResponse);

}

 

 

 

view.jsp

 

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

<portlet:defineObjects />

 

<form action="<portlet:actionURL/>" name="form" method="post">

<input type="text" name="public-render-param"> <input type="submit" value="submit">

</form>

 

showParameter.jsp

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

<portlet:defineObjects />

<%=renderRequest.getParameter("public-render-param")%>

Threaded Replies Author Date
I've used this feature in a current liferay... Rob Sonke December 8, 2008 9:51 AM
great work! looking forward to the next... Wilson Man December 11, 2008 1:54 PM
Nice job Steven =) David Truong December 17, 2008 1:19 PM
Thanks guys! The next one is coming! Dave your... Jian Cao December 17, 2008 5:42 PM

I've used this feature in a current liferay 5.0.1 website. Works easy but powerful!
Posted on 12/8/08 9:51 AM.
great work! looking forward to the next installment!
Posted on 12/11/08 1:54 PM.
Nice job Steven =)
Posted on 12/17/08 1:19 PM.
Thanks guys! The next one is coming! Dave your icon is awesome! emoticon
Posted on 12/17/08 5:42 PM in reply to David Truong.