Controlling Portlet State

 <  Day Day Up  >  

Portals might require that the state of different portal objects (pages, books, portlets) change programmatically. In some cases, for example, the page or book that's currently displayed is used by a portlet. In other cases, portlets should appear based on some event taking place, such as a weather alert portlet that's displayed only during severe weather warnings. To access the state of portal objects, backing contexts are used.

Backing Contexts

When working with portal applications, sometimes you need to manipulate whether a portlet object is minimized or maximized or whether it even exists in the code. WebLogic Portal provides a series of backing contexts to do just that. Backing contexts aren't simply for portlets, however; they can also be extended to pages and books. Table 13.3 lists the five main backing context classes.

Table 13.3. Contexts

BACKING CONTEXT CLASS

DESCRIPTION

BackingContext

The backing context class that all others extend from. It provides methods to set the visibility of the appropriate object.

WindowBackingContext

Provides base methods to retrieve label names , access definitions, current state, and windowed mode.

PortletBackingContext

Adds other methods, including accessing portlet preferences.

PageBackingContext

Adds methods to determine what images are displayed and whether the page is active.

BookBackingContext

Subclasses the PageBackingContext class and adds methods that have information on what pages are inside it.

To help you understand backing contexts, refer to the portal application used earlier in this chapter. Remember that the rules are displayed when the rules link is clicked. The new requirement is to see the rules portlet only if the link is clicked. A backing file has been created for this portlet where this modification will be coded, as shown in Listing 13.5. Each backing context class has a static method to access the context. The code checks to see whether the rules parameter exists; if it does, you'll make the portlet visible by passing true to the setVisible() method.

Listing 13.5. Using the Portlet Backing Context
 public boolean preRender     (HttpServletRequest request, HttpServletResponse response)     {         PortletBackingContext pb =             PortletBackingContext.getPortletBackingContext(request);         String rules = request.getParameter("rules");         if (rules != null)             pb.setVisible(true);         else             pb.setVisible(false);         return true;     } 

Another common scenario is making a portlet, page, or book visible only if a user is logged in. The code to do this is almost identical, except that instead of accessing the request parameters, you would use the request to see whether the user is logged in. This method can come in handy when you want to "hide" books or pages from users who aren't logged in. Backing contexts have many other uses and can enrich a user 's experience with a portal application. Other examples of using backing contexts to modify portal behavior are

  • Minimizing a portlet

  • Maximizing a portlet

  • Accessing the number of pages in a book

  • Accessing portlet, page, and book titles

 <  Day Day Up  >  


BEA WebLogic Workshop 8.1 Kick Start
BEA WebLogic Workshop 8.1 Kick Start: Simplifying Java Web Applications and J2EE
ISBN: 0672326221
EAN: 2147483647
Year: 2004
Pages: 138

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