+

Search Tips   |   Advanced Search

 

Launching pages

 

Typically, users of the console launch pages using the links in the console navigation. However, portlets in a console module also launch pages directly using the Dynamic UI Manager API.

The DynamicUI Manager APIs are provided by 3 services: PropertyFactory, DynamicUIManagerFactoryService, and URLGeneratorFactoryService. To use these services the portlet must first perform a JNDI lookup to get the PortletServiceHome object which you then can use to get the actual service interface object. This is demonstrated in the GetApps portlet of the PortletContext sample.. The following code is placed in a try block of the portlet's init() method.

Context ctx = new InitialContext(com.ibm.portal.jndi.Constants.ENV);
// get propertyfactory service
propertyFactoryServiceHome = (PortletServiceHome)ctx.lookup("portletservice/com.ibm.portal.propertybroker.service.PropertyBrokerService");

if (propertyFactoryServiceHome == null)
   logger.log(Level.FINE, "no PropertyBrokerService propertyFactoryServiceHome");
else
   propertyFactoryService = 
      (PropertyFactory)propertyFactoryServiceHome.getPortletService(com.ibm.portal.propertybroker.service.PropertyBrokerService.class);
      
logger.log(Level.FINE, "propertyBrokerService="+propertyFactoryService);
// get dynamicUIManagerFactory service
dynamicUIManagerFactoryServiceHome = 
   (PortletServiceHome)ctx.lookup("portletservice/com.ibm.portal.portlet.service.DynamicUIManagerFactoryService");
if (dynamicUIManagerFactoryServiceHome == null)
   logger.log(Level.FINE, "no dynamicUIManagerFactoryService propertyFactoryServiceHome");
else
   dynamicUIManagerFactoryService = 
      (DynamicUIManagerFactoryService)dynamicUIManagerFactoryServiceHome.getPortletService(com.ibm.portal.portlet.service.DynamicUIManagerFactoryService.class);
      
logger.log(Level.FINE, "dynamicUIManagerFactoryService="+dynamicUIManagerFactoryService);
// get urlGeneratorFactory service
urlGeneratorFactoryServiceHome = 
   (PortletServiceHome)ctx.lookup("portletservice/com.ibm.portal.portlet.service.URLGeneratorFactoryService");
if (urlGeneratorFactoryServiceHome == null)
   logger.log(Level.FINE, "no urlGeneratorFactoryService propertyFactoryServiceHome");
else
   urlGeneratorFactoryService = 
      (URLGeneratorFactoryService) urlGeneratorFactoryServiceHome.getPortletService(com.ibm.portal.portlet.service.URLGeneratorFactoryService.class);
      
logger.log(Level.FINE, "urlGeneratorFactoryService="+urlGeneratorFactoryService);

A portlet can launch a new page using the dynamicUICtrl interface, passing the object ID of the page definition for the new page. The object ID is determined by performing a JNDI lookup on the unique name of the navigation element that launches the page. If you are planning to launch a navigation element, the navigation node must point to a layout element. In other words the navigation element must contain the layoutElementRef attribute. The addPage() method returns the object ID of the page instance, which should be saved by the portlet to create a URL and launch the page. The following excerpt from the PortletContext sample demonstrates how this works. The portlet GetApps.java includes a launchPage() method with this code.

Context ctx;
ObjectID pageDefinitionID = null;
String pagename="com.ibm.isclite.portletcontext.navigationElement.B";
logger.log(Level.FINE, "launch page=" + pagename);

PortletSession ps  = request.getPortletSession(false);
try {
    ctx = new InitialContext();
    pageDefinitionID =(ObjectID)ctx.lookup("portal:uniquename/"+pagename);
} catch (NamingException ne) {
    return;
}
try {
    PropertyController cproperty = propertyFactoryService.createProperty(myconfig);
    PropertyController cproperty2 = propertyFactoryService.createProperty(myconfig);
       
    cproperty.setType("String");
    cproperty.setName("servername");
    cproperty2.setType("String");
    cproperty2.setName("appDeployed");
    PropertyValue[] propertyValues = new PropertyValue[2];
    propertyValues[0] = 
        propertyFactoryService.createPropertyValue(request, cproperty, serverName);
    propertyValues[1] = 
        propertyFactoryService.createPropertyValue(request, cproperty2, appDeployed);
       
    DynamicUICtrl dmanagerCtrl = 
       dynamicUIManagerFactoryService.getDynamicUICtrl(request, response, "isc.tasklaunch");
       
    ObjectID newPageID = 
        dmanagerCtrl.addPage(pageDefinitionID, null, propertyValues);
    
    RedirectURLGenerator urlGenerator = 
        urlGeneratorFactoryService.getURLGenerator(request, response);
       
    EngineURL redirectURL = urlGenerator.createPageURL(newPageID);
       
    response.sendRedirect(redirectURL.toString()); 
} catch  ...






 

Related information


Passing properties to other portlets
Application definition elements