Enabling cooperative sources

To enable a cooperative source, perform the following steps.

  1. In the Project Explorer view, select a portlet or the Portlet Deployment Descriptor. Portlets are displayed when you expand the Portlet Deployment Descriptor node under the portlet project folder.
  2. Right-click the desired portlet, and select Cooperative > Enable Source from the pop-up menu. The Enable Cooperative Source dialog opens. Alternatively, open a JSP page, ensure that it has focus, and select Page > Cooperative > Enable Source from the menu.
    Enable Cooperative Source dialog
  3. Provide values for the following fields:
    Data type
    Specify a name of the data type of the data to be transferred by the source portlet. Alternatively, if the data type you want to publish has been already declared, click the Browse button to open the Select Type dialog and select a WSDL data type that you wish to publish. The data type and the namespace in the WSDL file will be specified in each field. The specified value will be used to declare the data type in the <types> element in WSDL file.
    Namespace
    Specify the namespace for the type. For example, http://www.yourco.com/c2a. The specified value will be stored in a WSDL file and will be used as namespace to specify output property.
    [Source action] Name
    Specify the portlet action name.
    Name parameter (optional, for JSR 168 portlets)
    Specify the action name parameter. For JSR 168 Struts portlets, the action name parameter must be specified as spf_strutsAction.
    [Parameter] Name
    Specify the name of the parameters consumed or produced by the portlet action.
    Caption (optional)
    Specify the caption name of the parameters consumed or produced by the portlet action.
    Bound to
    Specify where the parameter value is bound. Currently, this attribute can specify one of the following values only:
    • render-parameter: [JSR 168 API only] This specifies that the value is bound as a render parameter in the ActionResponse (output parameters only).
    • request-parameter: This specifies that the value is bound as a parameter in the PortletRequest object. This is the default value if the boundTo attribute is omitted. Note that for output parameters, a different value should usually be specified as the default PortletRequest implementation provided by WebSphere® Portal does not allow parameters to be set during action processing.
    • request-attribute: This specifies that the value is bound as an attribute in the PortletRequest object.
    • session: This specifies that the value is bound to the PortletSession object.

    It is also possible to use this attribute, without using the Click-to-Action interface provided, when enabling the source portlet .

    The following example shows the actionPerformed() method of the OrderDetailPortlet.java in the Cooperative Portlets application sample from the Sample Gallery. The portlet passes the TRACKING_ID parameter to property broker in its actionPerformed() method. This parameter corresponds to an output parameter in the binding section of the portlet's WSDL file ( OrderDetail.wsdl, in this example).

    OrderDetailPortlet.java
    OrderDetailPortlet.java
    
    
    ...
    	private static final String PREFIX = ""; //$NON-NLS-1$
    	public static final String ACTION_NAME = PREFIX + "actionName"; //$NON-NLS-1$
    	public static final String ORDER_DETAILS = PREFIX + "orderDetails"; //$NON-NLS-1$
    	public static final String ORDER_ID_ENTRY = PREFIX + "orderIdEntry"; //$NON-NLS-1$
    	public static final String ORDER_ID = PREFIX + "orderId"; //$NON-NLS-1$
    	public static final String ORDER_DETAIL_BEAN = PREFIX + "orderDetailBean"; //$NON-NLS-1$
    	public static final String ORDER_DETAIL = PREFIX + "orderDetail"; //$NON-NLS-1$
    	public static final String TRACKING_ID = PREFIX + "trackingId"; //$NON-NLS-1$
    ...
    	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(Messages.getString("OrderDetailPortlet_action_entry")); //$NON-NLS-1$
    		}		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
    			 */
    			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);
    		}
    	}
    ...
    OrderDetail.wsdl (The property broker receives the tracking ID parameter from the request attribute.)
    ...
    <binding 
        name="OrderDetailBinding" 
        type="tns:OrderDetail_Service">
      <portlet:binding></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>
    
    ...
    Resource bundle (optional)
    Specify the base name of a national language resource file that contains captions and descriptions of actions and properties. The specified base name will be defined by the c2a-nls-file configuration parameter in the portlet deployment descriptor, and an empty resource bundle will be generated under the Java Resources node. For example, if you enter nls.shippingc2a, then edit the appropriate language-specific resource bundles: nls\shippingc2a<_lang>.properties to specify translated captions and descriptions in the key=translated text format.
    Source portlet (Required)
    Specify the concrete portlet to be enabled as the cooperative source.
  4. Click OK. The cooperatively-enabled portlet is shown with a source portlet icon ( Cooperative source portlet icon) in the Project Explorer view.

The Enable Cooperative Source action performs the following tasks for you:

  1. Modifies web.xml to add a servlet class entry to refer to the property broker classes:
    <servlet-class>com.ibm.wps.pb.wrapper.PortletWrapper</servlet-class>
    <init-param>
       <param-name>c2a-application-portlet-class</param-name>
       <param-value>servlet-class</param-value>
    </init-param>
  2. Modifies portlet.xml to add configuration parameters to each concrete portlet that exposes actions to the property broker through the WSDL file, and specifies the base name of a national language resource file.
    <config-param>
        <param-name>c2a-action-descriptor</param-name>
        <param-value>WSDL file</param-value>
    </config-param>
    <config-param>
        <param-name>c2a-nls-file</param-name>
        <param-value>resource bundle name</param-value>
    </config-param>
  3. Imports an additional library, pbportlet.jar, to /WEB-INF/lib in the portlet project for use by the property broker.
  4. Creates the specified WSDL file with the following sections:
    <definitions>
    Acts as root.
    <types>
    The data type is declared using XML Schema Datatypes (XSD).
    <message>
    An output message.
    <portType>
    Defines an abstract collection of operations. <output>.
    <binding>
    Always extended to <portlet:binding> to identify the section as a cooperative binding extension for portlet action invocation.
Related concepts
Developing cooperative portlets
Related tasks
Enabling existing portlets for cooperation
Enabling cooperative sources with a Faces action
Enabling cooperative targets
Inserting Click-to-Action encodeProperty
Inserting Click-to-Action encodeProperties
Editing Click-to-Action encodeProperty
Editing Click-to-Action encodeProperties
Related reference
Web Services Description Language (WSDL) 1.1
WebSphere Portal Information Center
XML Schema Part 2: Datatypes

(C) Copyright IBM Corporation 2002, 2005. All Rights Reserved.