Access to portlet APIs from a model
You can access the Portlet API directly from a model by retrieving the request attributes...
Both the JSR-168 and WebSphere Portal portlet adapters place these objects in the HttpServletRequest on each request using predefined keys from the class...
com.bowstreet.adapters.ConstantsHere are examples of retrieving each of the Portlet objects:
PortletRequest portletRequest = (PortletRequest) webAppAccess.getHttpServletRequest().getAttribute(Constants.PORTLET_REQUEST);
PortletResponse portletResponse = (PortletResponse) webAppAccess.getHttpServletRequest().getAttribute(Constants.PORTLET_RESPONSE);
PortletConfig portletConfig = (PortletConfig) webAppAccess.getHttpServletRequest().getAttribute(Constants.PORTLET_CONFIG);Note: When running your model outside of a portal, these objects will be null.
You will need to import the proper object types based on your JSR-168 or WebSphere Portal environment.
Parent topic: Introduction to portlets
- Imports for JSR-168 portlets:
com.bowstreet.adapters.Constants
javax.portlet.PortletRequest;
javax.portlet.PortletResponse;
javax.portlet.PortletConfig;- Imports for WebSphere Portal portlets:
com.bowstreet.adapters.Constants
org.apache.jetspeed.portlet.PortletRequest
org.apache.jetspeed.portlet.PortletResponse
org.apache.jetspeed.portlet.PortletConfig