< 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 ContextsWhen 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
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 Contextpublic 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
|
< Day Day Up > |