Enabling cooperative targets

Enabling cooperative targets includes the following activities:

  1. Enabling the cooperative target

  2. Implementing the action

  3. Providing translations

To enable a cooperative target:

  1. Enable the cooperative target, as described in 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 Target from the pop-up menu. The Enable Cooperative Target dialog appears. Alternatively, open a JSP file and select Page > Cooperative > Enable Target from the toolbar.

    3. Provide values for the following fields:

      Data type (Required)

      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". When an existing WSDL file is specified below, the field gets disabled. The specified value will be stored in WSDL file and will be used with type attributes to match data to actions on targets by the cooperative runtime.

      Action (Required)

      Specify the portlet action name. If any Faces actions associated with command-controls and any Struts actions defined in Struts configuration files are available, you can select it from the Select Action dialog. To open this dialog, click the Browse button. The specified value will be stored in WSDL file as the name attribute of <portlet:action> element.

      Parameter (Required)

      Specify the name of the parameters consumed or produced by the portlet action. The specified value will be stored in WSDL file as the name attribute of <portlet:param> element.

      Bound to

      Specify where the parameter value is bound. Currently, this attribute can specify one of the following values 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.

      Label

      Specify a short string about the action suitable for displaying in the portlet user interface. For translated captions, specify the name of the key in the resource bundles using a dot (.) rather than a space between words in this field. Specify the translated captions in the key=translated caption format in the resource bundles that are specified in the Resources bundle field in this dialog. The specified value will be stored in WSDL file as the caption attribute of <portlet:action> element.

      Screen capture when C2A caption is displayed

      Description

      Specify a text description of the action. For translated descriptions, specify the name of the key in the resource bundles using a dot (.) rather than a space between words in this field. Specify the translated description in the key=translated description format in the resource bundles that are specified in the Resources bundle field in this dialog. The specified value will be stored in WSDL file as the description attribute of <portlet:action> element.

      Resource bundle

      Specify the base name of an NLS resource file containing translated texts that correspond to labels 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 you will edit the language-specific resource bundle: nls\shippingc2a<_lang>.properties under the JavaSource node to specify translated captions and descriptions in the key=translated text format.

      Target portlet (Required)

      Specify the concrete portlet to be enabled as the cooperative target.

      For example, you can specify the following values:

      Enable Cooperative Target dialog

    4. Click OK. The Click-to-Action-enabled portlet is shown with a target portlet icon (

      Click-to-Action Target Portlet icon) in the Project Explorer view.

  2. Ensure that the code for the target portlet class meets the following requirements:

    • The action must be implemented either as a portlet action, a Faces action or a Struts action. For portlet actions, you should use the simple action Strings rather than the deprecated PortletAction class.

    • 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.

    The following example shows the actionPerformed() method of the OrderDetailPortlet.java in the Cooperative Portlets application sample from the Sample Gallery. This portlet accepts the ORDER_ID parameter in its actionPerformed() method. This parameter corresponds to an input parameter in the binding section of the portlet's WSDL file ( OrderDetailC2A.wsdl in this example).

    ...
    
       private static final String PREFIX = "";
       public static final String ORDER_ID = PREFIX + "orderId";
       public static final String TRACKING_ID = PREFIX + "trackingId";
    
    ...
        
        public void actionPerformed (ActionEvent event) 
        {
    //        DefaultPortletAction action = (DefaultPortletAction) event.getAction();
       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);
       }
        }
    ...

  3. Provide translated text that corresponds to the label and description in the resource bundle files. The base name of resource bundle is specified in the Resource bundle field and it is stored by the c2a-nls-file configuration parameter in the portlet deployment descriptor. Edit the language-specific resource bundles under the JavaSource node. To specify translated captions and descriptions, use the key=translated text format and keys that are specified as the Label and Description.

The Enable Cooperative Target 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 a configuration parameter to each concrete portlet that receives the input property broker through the WSDL file and to specify 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>

    • To add a configuration parameter for a Faces portlet to specify the target action name and its parameter name.

  3. Imports an additional library, pbportlet.jar, to /WEB-INF/lib in the portlet project for use of the property broker.

  4. Creates a 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.

  5. Generates a resource bundle file that includes the key value (from the key=translated string text format) that was specified in Label field in the Enable Cooperative Target dialog.

 

Related concepts

Developing cooperative portlets

 

Related tasks

Enabling existing portlets for cooperation
Enabling cooperative sources
Inserting Click-to-Action encodeProperty
Inserting Click-to-Action encodeProperties
Editing Click-to-Action encodeProperty
Editing Click-to-Action encodeProperties

Related information
Web