Sample: Interactive Form Portlet (FormExample)
Step 5: Create the JavaBean
The FormExample portlet was developed using a JavaBean called ExampleBean.java . This JavaBean places values in the PortletContext object so that the values are available to the JSP page.
The HttpServletRequest or HttpSession object could be used for this purpose. However, the PortletContext object is unique to the portlet and is not shared with other processes. Therefore, using it avoids collisions that could cause attribute values to be overwritten.
The source code for ExampleBean.java follows.
/**Copyright (c) 2003 by SAS Institute Inc., Cary, NC 27513.
* All Rights Reserved.
*/
package com.sas.portal.portlets.formexample;
public final class ExampleBean {
/**Sets the user's input to this property. If input
* is null, it will be changed to "" so that getUserInput()
* never returns null.
*
* @param input
*/
public void setUserInput(String input) {
if (input == null) {
input = "";
}
this.input = input;
}
/**Returns the user's input or "".
*
* @return String
*/
public String getUserInput() {
return input;
}
private String input = "";
}
|