2.12 Core event objects

 <  Day Day Up  >  

This section will cover the objects you will need to work with when managing event handling in action events.

2.12.1 ActionListener

The org.apache.jetspeed.portlet.event.ActionListener interface defines a single method to be implemented as illustrated in Example 2-24.

Example 2-24. ActionListener Interface
 org.apache.jetspeed.portlet.event.ActionListener public void  actionPerformed  (org.apache.jetspeed.portlet.event.ActionEvent           event) throws PortletException; 

2.12.2 ActionEvent

An implementation of the org.apache.jetspeed.portlet.event.ActionEvent interface is passed to the actionPerformed method by the PortalServer when a PortletURI with an action is executed. The ActionEvent object provides access to the PortletRequest and the action.

Note: The DefaultPortletAction class and the PortletAction interfaces are deprecated in this release and you should use the Simple Action string instead, as illustrated in Example 2-25.

Example 2-25. Working with the ActionEvent
 public void  actionPerformed  (ActionEvent event) throws PortletException {    PortletRequest request = event.getRequest();    String action = event.getActionString(); 

2.12.3 PortletURI

The portletURI represents a URL that can be used to navigate between modes. The PortletURI can be used to navigate to a previous mode, such as from Edit to View, or to navigate back to the same mode, such as a multi-part form in View or Edit. There is no ability to create a PortletURI object pointing to a mode not yet visited by the user .

PortletRequest.createURI returns a portletURI object pointing to the portlet in its current mode. For example, if the portletURI is created in the doView mode, the URL points to the portlet in View. The createReturnURI method returns a PortletURI object pointing to the last mode the portlet was in. This mode is commonly used in the doEdit method when the URI needs to point back to the View mode. The edit.jsp would use the PortletURI to bring the user back to the View mode when they have completed the edit or configure process.

In order for a portlet to be notified of an event, such as the user clicking a button, the portletURI must contain an associated PortletAction. Typical PortletURI construction and usage is shown in Example 2-26.

In this release of the Portlet API, the process of adding actions to PortletURI objects has been simplified. The addAction(PortletAction) method has been deprecated and replaced with addAction(String). Since the vast majority of work with PortletActions involves no more than setting a name , this new implementation is much more convenient .

Developers are advised to use simple action string instead. For details, see Chapter 5, "Action event handling" on page 181.

Note

Deprecated classes and interfaces are still supported in the current release but are not recommended for use because they might not be supported in future releases.


Since the DefaultPortletAction class and the PortletAction interfaces are deprecated in this release, we show the use of the Simple Action string instead, as illustrated in Example 2-26.

Example 2-26. Working with PortletURI
 PortletURI uri = response.createReturnURI(); uri.addAction("save"); request.setAttribute("uri", uri.toString()); 

It is possible to add parameters to the PortletURI object. Parameters added to the PortletURI via code or through a form are accessed the same way via the portlet request object. This provides a mechanism to pass default values or to pass parameters not displayed in the form. Example 2-27 displays the code for adding a parameter. Be aware that parameters set via the PortletURI are not passed in the traditional HTML syntax.

Note: The DefaultPortletAction class and the PortletAction interfaces are deprecated in this release and you should use the Simple Action string instead, as illustrated in Example 2-27.

Example 2-27. Add URI
 public void  doView  (PortletRequest request, PortletResponse response) throws                       PortletException, IOException {    PortletURI viewURI = response.createReturnURI();    viewURI.addAction("save");    viewURI.addParameter("Param1", "Param1Value");    request.setAttribute("viewURI", viewURI.toString());    getPortletConfig().getContext().include("/jsp/View.jsp", request,                       response);    } 

2.12.4 ModeModifier

When a PortletURI is created, it points to a portlet in particular mode. When that PortletURI is executed and it contains a PortletAction, it will notify the appropriate listener. If, in the actionPerformed method, you need to redirect the user to a mode other the one specified, the request.setModeModifier method can be used to redirect the user to another mode. The ModeModifier can only be set during event processing. Calling this method in doView or doEdit, etc., will have no effect. There are three possible modes the user can be redirected to:

  • REQUESTED This ModeModifier will navigate the user to whatever mode was originally set by the PortletURI. Essentially, this is the default. If the ModeModifier is changed, it cannot be changed back to REQUESTED.

  • CURRENT This ModeModifier will keep the user in the current mode. For example, if the user tries to save some information and the actionPerformed determines it is incorrect, setting ModeModifier to CURRENT will return them to the Edit screen.

  • PREVIOUS This ModeModifier will return the user to the mode the user was in prior to the CURRENT regardless of previous ModeModification. Therefore, setting ModeModifier to CURRENT in one event process will not make that mode PREVIOUS in the next event process.

 <  Day Day Up  >  


IBM WebSphere Portal V5 A Guide for Portlet Application Development
IBM Websphere Portal V5: A Guide for Portlet Application Development
ISBN: 0738498513
EAN: 2147483647
Year: 2004
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net