WebSphere

 

Portal Express, Version 6.0
Operating systems: i5/OS, Linux, Windows

 

Assigning property values

This topic describes how to assign a property value when developing cooperative portlets.

Make sure you have registered your properties. A property must be registered before the property broker will recognize it. This can be done either in the WSDL file (for standard portlets or IBM portlets) or programmatically (for IBM portlets only).

Property values are data that can be transferred to other portlets using the property broker. Portlet actions which can accept that transferred data may also be declared in the WSDL file. For IBM portlets only, the alternative is to register the actions programmatically. The syntax used is standard WSDL. A concrete implementation of the abstract operation definitions may be specified using bindings. The binding thus includes the protocol and the data format to be used for invoking the operations - in essence, all the information an invoking program would need to invoke a concrete implementation of the operations.

Certain restrictions must be followed by the operation declarations for cooperative portlets. At present, only a single input parameter is allowed for each operation. The types associated with parameters must be declared using XSD (see the XSD specification).

A custom binding section must also be used to specify how to invoke the declared operations on the implementing portlet. The binding section maps each abstract operation to an action on the portlet. For each operation, the portlet action name must be provided. For each operation parameter, the action parameter name must be provided. Further, an attribute may be used to specify where the parameter will be bound. Choices are request parameter, request attribute, session attribute, action attribute (IBM only; The action attribute is deprecated), and render parameter (JSR compliant only). Reasonable defaults apply for most attributes.

Option Description
Standard portlets

A target portlet's processAction() method is used to receive property change notifications. A WSDL file is provided that enumerates the properties and actions associated with a portlet. The JSR compliant WSDL file must specify the type attribute of the action element with a value of standard. If the portlet is implemented using the struts framework, change the value of the type attribute to standard-struts.

The code for the target portlet class must meet the following requirements:

  • The action must be implemented either as a portlet action or a Struts action. JavaServer Faces actions may also be used using the appropriate JavaServer Faces tools. Portlet actions must accept a single parameter. The parameter may appear as a request parameter, a request attribute, a session attribute, or a render parameter, as specified in the action declaration or registration. For more information on Rational Application Developer using JavaServer Faces see the Creating Faces portlets and projects section in Rational Application Developer documentation

  • The actionNameParameter attribute must be specified for JSR portlet actions, and indicates the name of a request parameter which will be used to carry the name of the action when it is invoked. This is important for JSR portlets as actions in this case are not explicitly associated with names (this is different from the IBM portlet case), and the application must use an additional parameter to identify the actual logic to execute. IBM recommends, but not required, that the actionNameParameter value be set to the same value for all actions which a portlet declares.

The code example, Figure 1 and Figure 2, can be found in the in the Shipping demo. This portlet accepts the ORDER_ID parameter in its processAction() method. The parameter ORDER_ID corresponds to an input parameter in the binding section of the portlet's WSDL file.

IBM portlets

The code for the target portlet class must meet the following requirements:

  • The action must be implemented either as a portlet action or a Struts action. JavaServer Faces actions may also be used using the appropriate JavaServer Faces tools. For portlet actions, you should use the simple action Strings rather than the deprecated DefaultPortletAction class. For more information on Rational Application Developer using JavaServer Faces see the Creating Faces portlets and projects section in Rational Application Developer documentation.

  • Portlet actions must accept a single parameter. The parameter may appear as a request parameter, a request attribute, a session attribute, or an action attribute (deprecated), as specified in the action declaration or registration.

Figure 3 shows code from the sample that can be found in the in the Shipping demo. This portlet accepts the ORDER_ID parameter in its actionPerformed() method. The parameter ORDER_ID corresponds to an input parameter in the binding section of the portlet's WSDL file.

Figure 4 is the same as the WSDL file for the standard portlets example except for the value of type set in the binding. One of the supported values for type for IBM portlets is simple.

Figure 1. processAction() example from OrderDetailPortlet.java

  ...

   private static final String PREFIX = "";
   public static final String ACTION_NAME = PREFIX + "actionName";
   public static final String ORDER_DETAILS = PREFIX + "orderDetails";
   public static final String ORDER_ID_ENTRY = PREFIX + "orderIdEntry";
   public static final String ORDER_ID = PREFIX + "orderId";
   public static final String ORDER_DETAIL = PREFIX + "orderDetail";
   public static final String TRACKING_ID = PREFIX + "trackingId";
   public static final String PBSERVICE = PREFIX + "pbService";
      
  ...

public void processAction (ActionRequest request, ActionResponse response) 
{
   String actionName = request.getParameter("ACTION_NAME");
   if (actionName == null) {
      actionName = "";
   }

   //An action causes the state to be modified    ShippingUtils.setLastModified(request);

   getPortletContext().log("OrderDetail processAction called");

   if (actionName.equals(ORDER_DETAILS)) {
      request.getPortletSession().setAttribute(ACTION_NAME, ORDER_DETAILS);
      request.getPortletSession().setAttribute(ORDER_ID, 
						request.getParameter(ORDER_ID));

      //We do this as tracking id is an out param in the init()
      //We write the tracking id in the request so it can be published by       //the broker in the same event cycle       String orderId = (String) request.getPortletSession().getAttribute(ORDER_ID);
      OrderDetail od = ShippingDB.getOrderDetail(request.getParameter(ORDER_ID));
      if (od != null) {
         request.getPortletSession().setAttribute(ORDER_DETAIL, od);
         request.setAttribute(TRACKING_ID, od.getTrackingId());
      }

      } else if (actionName.equals(ORDER_ID_ENTRY)) {
         request.getPortletSession().setAttribute(ACTION_NAME, ORDER_ID_ENTRY);
      }
    }

  ...
Figure 2. WSDL file example from OrderDetail.wsdl

...
<definitions name="OrderDetail_Service"
  targetNamespace="http://www.ibm.com/wps/c2a/examples/shipping"
  xmlns="http://schemas.xmlsoap.org/wsdl/"
  xmlns:portlet="http://www.ibm.com/wps/c2a"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns:tns="http://www.ibm.com/wps/c2a/examples/shipping"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  
  ...
  
  <types>
  <xsd:schema targetNamespace="http://www.ibm.com/wps/c2a/examples/shipping">
    <xsd:simpleType name="OrderIDType">
      <xsd:restriction base="xsd:string">
      </xsd:restriction>
    </xsd:simpleType>
   ...
  </types>

 

... <message name="OrderDetailsRequest"> <part name="order_Id" type="tns:OrderIDType"/> </message>

 

... <binding name="OrderDetailBinding" type="tns:OrderDetail_Service"> <portlet:binding/> <operation name="order_Detail"> <portlet:action name="orderDetails" type="standard" caption="Order.Details" description="Get.details.for.specified.order.id" actionNameParameter="ACTION_NAME"/> <input> <portlet:param name="orderId" partname="order_Id" caption="order.id"/> </input> <output> <portlet:param name="trackingId" partname="tracking_Id" boundTo="request-attribute" caption="tracking.id"/> </output> </operation> </binding>

 

...
Figure 3. actionPerformed() example from the OrderDetailPortlet sample

  ...

	private static final String PREFIX = "";
    public static final String ACTION_NAME = PREFIX + "actionName";
    public static final String ORDER_DETAILS = PREFIX + "orderDetails";
    public static final String ORDER_ID_ENTRY = PREFIX + "orderIdEntry";
    public static final String ORDER_ID = PREFIX + "orderId";
    public static final String ORDER_DETAIL = PREFIX + "orderDetail";
    public static final String TRACKING_ID = PREFIX + "trackingId";

  ...

    public void actionPerformed (ActionEvent event) 
    {
	String actionName = event.getActionString();

        PortletRequest request = event.getRequest();

        //An action causes the state to be modified         ShippingUtils.setLastModified(request);

 		if( getPortletLog().isDebugEnabled() ) {
    	    getPortletLog().debug("OrderDetailActionListener - Action called");
 		}
 		
        if (actionName.equals(ORDER_DETAILS)) {
          request.getPortletSession().setAttribute(ACTION_NAME, ORDER_DETAILS);
          request.getPortletSession().setAttribute(ORDER_ID, request.getParameter(ORDER_ID));

	    //We do this as tracking id is an out param in the C2A WSDL file 	    //We write the tracking id in the request so it can be published by 	    //the broker in the same event cycle             String orderId = (String) request.getPortletSession().getAttribute(ORDER_ID);
	    OrderDetail od = ShippingDB.getOrderDetail(request.getParameter(ORDER_ID));
            request.getPortletSession().setAttribute(ORDER_DETAIL, od);
	    request.setAttribute(TRACKING_ID, od.getTrackingId());

        }  else if (actionName.equals(ORDER_ID_ENTRY)) {
            request.getPortletSession().setAttribute(ACTION_NAME, ORDER_ID_ENTRY);
	}
    }

 

...
Figure 4. WSDL file example from OrderDetail.wsdl

...
  <binding     name="OrderDetailBinding"
      type="tns:OrderDetail_Service">
  <portlet:binding/>
  <operation name="order_Detail">
    <portlet:action name="orderDetails" type="simple" 
                    caption="Order.Details" 
                    description="Get.details.for.specified.order.id"/>
    <input>
      <portlet:param name="orderId" partname="order_Id" caption="order.id"/>
    </input>
    <output>
      <portlet:param name="trackingId" partname="tracking_Id" 
                     boundTo="request-attribute" caption="tracking.id"/>
    </output>
  </operation>
</binding>

 

...

 

Related Links