Development Steps: Creating Action Classes
Creating an Initializer Action Class
When you develop a local portlet, you can implement an initializer class that runs before the portlet is displayed for the first time on a portal Web application page. The initializer does not execute again if the user interacts with your portlet or with other portlets on the same page. It also does not execute again if the user navigates to another page and then back again. However, the initializer does run again if the user logs off, logs on again, and displays the page that contains the portlet.
Uses for an initializer might include reading initial parameters that are specified in your portlet's deployment descriptor file (portlet.xml ), or connecting to an external resource such as a database.
The portal Web application is delivered with a default initializer class called JspPortletInitializer , which requires a parameter called display-page . The initializer places the value of this parameter in the PortletContext object so that it can be used by the portlet's action class. To pass additional parameters, you would need to create your own initializer class.
When you create an initializer class, ensure that the following steps have been taken:
The com.sas.portlet.portlet.PortletInitializerInterface class includes one method called initialize() . The following objects are passed to this method:
java.util.Properties , which contains all of the initial parameters that are specified in your portlet's deployment descriptor. If your portlet's action class or JSP page requires access to these parameters, you should place them in the portlet context object using its setAttribute() method.
com.sas.portal.portlet.PortletContext , which provides a getter method for the HttpSession object so that you can access or set session attributes.
Here is an example of an initialize() method that places initial parameters into the portlet context.
/**Puts initial properties into the PortletContext object.
* These come from the portlet.xml.
* @param initProperties a Properties object
* @param context the PortletContext for this portlet
*/
public void initialize(Properties initProperties,
PortletContext context) {
context.setAttribute("display-page",
initProperties.getProperty("display-page"));
context.setAttribute("image-location",
initProperties.getProperty("image-location"));
}
|