JBoss Community Archive (Read Only)

Portlet Bridge 3.3

Public Render Parameters

Public Render Parameters (or PRPs) are one of the most powerful and simple Portlet 2.0 features. Several portlets (JSF or not) can share the same render parameters. This feature can be use to present a cohesive UI to the user across all portlets on the page (i.e. using an employee ID to display relative data).

Public Render Parameters can only be used to set/retrieve a String value, and not an object as Events can.

Portlet Configuration

The portlet that sets the Public Render Parameter, and also the one receiving it, need the following defined within their portlet.xml:

<portlet>
  ...
  <supported-public-render-parameter>hotelName</supported-public-render-parameter>
</portlet>

<public-render-parameter>
  <identifier>hotelName</identifier>
  <qname xmlns:j="http://jboss.org/params">j:hotelName</qname>
</public-render-parameter>

The portlet that will be retrieving the Public Render Parameter also needs to define a handler in the portlet.xml as below:

<init-param>
  <name>javax.portlet.faces.bridgePublicRenderParameterHandler</name>
  <value>org.jboss.example.booking.BookingPRPHandler</value>
</init-param>

Set Parameter

Setting the Public Render Parameter only needs a Bean method, most likely called as part of an Action from the UI, that sets the render parameter onto the response, as below:

Object response = FacesContext.getCurrentInstance().getExternalContext().getResponse();
if (response instanceof StateAwareResponse) {
  StateAwareResponse stateResponse = (StateAwareResponse) response;
  stateResponse.setRenderParameter("hotelName", "Name of Hotel");
}

Retrieve Parameter

The portlet(s) retrieving the parameter will need a Bean with a getter/setter for the parameter so it can be set by the Bridge, such as below:

public class BookingPRP {
  private String hotelName;

  public String getHotelName() {
    return hotelName;
  }

  public void setHotelName(String hotelName) {
    this.hotelName = hotelName;
  }
}

To set the value on the Bean, the Bridge needs to be informed which Public Render Parameter you want to retrieve and which Bean you want it set on. If the above Bean is defined with a EL name of bookingPRP, then the faces-config.xml would be:

<application>
  <application-extension>
    <bridge:public-parameter-mappings>
      <bridge:public-parameter-mapping>
        <parameter>bookingMapPortlet:hotelName</parameter>
        <model-el>#{bookingPRP.hotelName}</model-el>
      </bridge:public-parameter-mapping>
    </bridge:public-parameter-mappings>
  </application-extension>
</application>

In the preceding example, the namespace associated with the "bridge" prefix is "http://jboss.org/portletbridge".

 

bookingMapPortlet:hotelName as the parameter above needs to represent the name of your portlet (within portlet.xml) and name of the render parameter concatenated with a colon. If the portlet name is omitted and only the render parameter specified, every portlet within the web application that supports that render parameter will have their model updated. Specifying the portlet name as well restricts model updates to just that portlet.

Finally, we need the handler that was specified in the portlet.xml earlier to process the updates to the model as a result of the Public Render Parameter. Below is an example handler:

public class BookingPRPHandler implements BridgePublicRenderParameterHandler {
  public void processUpdates(FacesContext context) {
    ELContext elContext = context.getELContext();
    BookingPRPBean bean = (BookingPRPBean) elContext.getELResolver().getValue(elContext, null, "bookingPRP");

    if(null != bean) {
      System.out.println("******processUpdates from BookingPRPHandler: " + bean.getHotelName());
    }
  }
}
JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-11 12:28:52 UTC, last content change 2012-10-19 15:05:20 UTC.