In this blog i will talk about the support for public render parameter (new feature that was added in Portlet 2.0 specification) in the JSF Portlet Bridge.

In JSFPortletBridge version 1.2.3 an enhancement was added to keep track of request scoped information. Check the issue 30 for more details. This feature can be used to support the sharing of render parameters among jsf portlets. I will explain how to do it. The example war and source is referenced at the end.

1. First you need to set the following initialization parameter in the portlet.xml for the portlet that wants to share the render parameter
       <init-param>
            <name>com.sun.faces.portlet.SAVE_REQUEST_SCOPE</name>
            <value>true</value>
        </init-param>      

This causes the form parameters to be set as render parameters. As a result all form parameters are available in the render of the portlet.

2. Now identify the parameter to be shared and specify it in the portlet.xml. Since JSF generates the name, you need to specify the generated name in the portlet.xml..For example consider the following snippet

<f:view>
    <h:form id="helloForm">
        .............
    <h:inputText id="userNo" value="#{UserNumberBean.userNumber}"
             validator="#{UserNumberBean.validate}"/>
    .................
    </h:form>
</f:view>

If you want to share the inputText "userNo", then specify the parameter "helloForm:userNo" as supported-public-render-parameter.

If you notice i have dropped the tag <p:portletPage> . This tag causes the portlet namespace to be prepended to the parameter name. The parameter name will be "portletnamespace:helloForm:userNo". The namespace that is generated by the portlet container will be different in each portal. So i have removed it.

The parameter can be specified in the portlet.xml as follows..
<portlet-app>
    <portlet>
    ...........
        <supported-public-render-parameter>helloForm:userNo</supported-public-render-parameter>
    </portlet>
    <public-render-parameter>
        <identifier>helloForm:userNo</identifier>
        <qname xmlns:x="http://www.sun.com/params">x:userNumber</qname>
    </public-render-parameter>
</portlet-app>


3. If another JSF Portlet also specifies the same parameter as supported-public-render-parameter, then it can access the parameter as

    FacesContext context = FacesContext.getCurrentInstance();
    PortletRequest request = (PortletRequest)context.getExternalContext().getRequest();
    return request.getParameter("helloForm:userNo");

This will return the value entered in the first JSF Portlet.

Deploy the guessnumbersharedportlet.war on OpenPortal Portlet Container 2.0 and see the public render parameter at work. You can check the sources to see how this is done. The sample will work on Project WebSynergy and Liferay Portal also.



Comments:

Hi Deepak,
Is it possible to use Events in JSF portlets. Could you please provide some information on this?

Thank you

Posted by APps on June 30, 2009 at 10:59 PM IST #

Yes it is possible to use events in JSF Portlets. This ability with be available in the jsfportletbridge shortly.

Posted by Deepak on July 03, 2009 at 12:26 PM IST #

hello and thanks for this example.
i used it, but i got an error:

SCHWERWIEGEND: /home.xhtml @80,77 value="#{UserNumberBean.userNumber}": Illegal Syntax for Set Operation
19:24:28,375 INFO [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=...:_viewRoot:helloForm:userNo[severity=(ERROR 2), summary=
(/home.xhtml @80,77 value="#{UserNumberBean.userNumber}": Illegal Syntax for Set Operation), detail=(/home.xhtml @80,77 va
lue="#{UserNumberBean.userNumber}": Illegal Syntax for Set Operation)]

do you know, what could be the problem ?
thx!

Posted by gabe on September 01, 2009 at 11:04 PM IST #

iam sorry!
was only a beginner mistake.
wrong input, wrong naming.

Posted by gabe on September 01, 2009 at 11:21 PM IST #

did the portlets have to be in the same web-application?

Posted by gabe on September 01, 2009 at 11:40 PM IST #

The portlets need not be in the same webapp. In fact the example and sample shown above used two different jsf-portlet webapplication.

Posted by Deepak on September 02, 2009 at 10:40 AM IST #

Hello Deepak,

does the example also work on jboss-portal?

Posted by 84.154.226.36 on September 05, 2009 at 09:01 PM IST #

Sorry Deepak,
but the example shows a single .war with the two portlet in it...It's important to me to understand if I' m able to use this approach with portlet within different .war files...

Posted by uskassat on September 15, 2009 at 03:13 PM IST #

You can use this approach with portlet in different wars. As the public render parameter functionality across portlet wars is handled by the portlet container, it should work. I have not tried though. As this was done long time back i thought it was two different wars. Sorry about that. Let me know if it does not work in different wars.

Posted by Deepak on September 15, 2009 at 06:06 PM IST #

This approach works with portlets into different wars using the same jars, but I want to know how can I retrieve the parameter in the display portlet without importing manged bean related jars?

Posted by uskassat on September 15, 2009 at 06:47 PM IST #

Post a Comment:
  • HTML Syntax: NOT allowed

This blog copyright 2009 by deepakg