Register properties and actions

 

+

Search Tips   |   Advanced Search

 

This topic describes how to register properties and actions. Properties and actions need to be registered to make them available to the property broker.

The declarative method must be used with standard portlets and is recommended for IBM portlets.

Option Description
Declarative method (WSDL)

All portlets

  1. Register portlet properties using WSDL.

    WSDL with some custom extensions is a supported format for registering portlet properties using the declarative method. The syntax used is standard WSDL, with the custom extensions following a syntax permitted by WSDL. Some of the extensions are introduced specifically for cooperative portlets. These extensions follow the extension rules allowed by the base WSDL schema.

  2. Include the WSDL file in the WAR file.

    Action, parameter, and property information is obtained by parsing the WSDL file. All actions, parameters, and properties registered in the WSDL file are owned by the portlet specified in the portlet.xml file.

If the source portlet does not have any actions to expose as inter-portlet communication targets, but still wishes to register properties, a dummy action may be defined with input and output parameters. The declared input and output parameters cause the corresponding input and output properties to be registered. A potential side-effect of this approach may result in the action associated with input parameters appearing in Click-to-Action menus by default. This action would be invocable through any wires of which it is the target. To prevent this, set the attribute activeOnStartup to false

JavaServer Faces actions can be used in place of regular portlet or struts actions. When using JavaServer Faces, Rational Application Developer 6.0 tooling should be used to create the portlet and the WSDL file.

To see an example of a WSDL file, see Assigning property values.

Programmatic method

IBM portlets only

Registration of properties and actions can be done programmatically only for IBM portlets. Actions and properties for registration may be created through the PropertyFactory interface

To register actions, use the registerActions() method from the PropertyBrokerService interface. Each action must have a unique name. The actions are made available for invocation as the target of wires from other portlets. At this time, any properties associated with the actions which have not been registered earlier are automatically registered and any action registered earlier will be removed. Actions registered once are stored persistently as long as the portlet remains installed in the portal. To check if actions have already been registered using the getActions() method before invoking registerActions(). Actions registered are applicable for all instances of the calling portlet on all pages.

Properties can be registered programmatically using the registerProperties() method from the PropertyBrokerService interface. Programmatic registration of actions is also supported and is accomplished using analogous methods in the PropertyFactory interface. This registration applies to all instances of the portlet, not just to the invoking instance. As a result, registration should be done once during the lifecycle of the portlet at the beginning of the life cycle.

The following example shows the registerProperties() method from ClickMapPortlet.java.

public void beginEventPhase(PortletRequest request) 
{
    try     {
      registerPropertiesIfNecessary(request);
    }
    catch (PropertyBrokerServiceException e)
    {
      log.text(Logger.ERROR, "beginEventPhase",
               "Unable to register properties: nested exception is:",
               e);
      return;
    }
    
  ...
   
  /*
   * Properties need to be registered only once, and affect all    * portlet instances sharing the same portlet definition.
   */
  private void registerPropertiesIfNecessary(PortletRequest request) 
  throws PropertyBrokerServiceException 
  {
    PortletSettings settings = request.getPortletSettings();
    Property[] properties = getPropertyBrokerService().getProperties(request, settings);
    if (properties == null || properties.length == 0)
    {
      PortletContext context = getPortletConfig().getContext();
      Locale[] locales = new Locale[] {Locale.EN};

      //not registered, register now       properties = new Property[2];
      //an input property       properties[0] = PropertyFactory.createProperty(settings);
      properties[0].setName("newCity");
     ...

      //an output property
      properties[1] = PropertyFactory.createProperty(settings);
      properties[1].setName("outCity");
     ...

      getPropertyBrokerService().registerProperties(request, settings, properties);
    }
    
    ... 
  }     

Unlike input parameters, we can declare any number of output parameters for a target portlet. Output parameters are used to allow the target to react to an action by transferring data to other portlets, creating a chained propagation that updates multiple portlets from a single action. (The propagation occurs only if a suitable wire is present.) If the portlet action changes or accesses other state variables as a result of the action, it may be appropriate to declare them as output parameters. The portlet programmer may need to distinguish portions of the data model for the portlet which could be of interest to other portlets. These are often appropriate candidates for output parameters. For example, as a consequence of executing an "Order Detail" action, a portlet may retrieve information which contains an associated tracking ID. Since this is a key which may potentially be of interest to other portlets, it may be declared as an output parameter.

 

Related Links