8.5.5 interface javax.portlet.PortletRequest

The portlet request object will contain information about the client request. The request will also include parameters, the portlet mode, the window state, session, and access to the portlat context. PortletRequest defines commonly used functionality for ActionRequest and RenderRequest.

Parameters received during an action request will not be sent to the render request unless they are explicitly added using the setRenderParameters or setRenderParameters of the ActionResponse class. This can only be done in the processAction method.

If the render request follows an action request as part of the same request, the parameters sent in the render request will be the render parameters set during the action request.

A portlet will only be able to see parameters in its own request. Parameters set for other portlets will not be visible.

Parameter and attribute names beginning with javax.portlet are reserved and should not be used.

Request properties are used for portal specific properties. These properties may include http headers.

Example 8-6 Code to get the properties and values of a request

Enumeration enum = request.getPropertyNames();
while(enum.hasMoreElements()){
 String name=(String)enum.nextElement();
 Enumeration values = request.getProperties(name);
 StringBuffer valueBuffer = new StringBuffer();
 while(values.hasMoreElements()){
 //seperate values with a ';'
 valueBuffer.append((String)values.nextElement() + "; ");  }
 System.out.println("Name: " + name + ", Value: " + valueBuffer.toString());
}

Example 8-7 Output from the above code while running a sample portlet

Name: accept-encoding, Value: deflate; gzip; 
Name: connection, Value: Keep-Alive; 
Name: referer, Value: http://localhost:9081/wps/myportal/!ut/p/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLN4g39DEDSUGYpvqRaGLGmEKOCBFvfV-P_NxU_QD9gtzQ0IhyR0UAATozOQ!!/delta/base64xml/L0lJWWtpaWxDbEEhIS9JRGpBQUFUQUFNSkFBTXdzaXNwc1lBISEvNElVR1JZUWxHamdJLzZfMF8xTDYvN18wXzFSRQ!!; 
Name: host, Value: localhost:9081; 
Name: accept-language, Value: en-us; 
Name: user-agent, Value: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0); 
Name: cookie, Value: JSESSIONID=00004jB0KukifHc_3h_7QBn9D-z:-1; 
Name: wps.markup, Value: html; 
Name: accept, Value: */*; 

The following methods should be used for getting and setting request parameters:


Redbooks
ibm.com/redbooks