databeans
Class BeanUtilities

java.lang.Object
  extended bydatabeans.BeanUtilities

public class BeanUtilities
extends java.lang.Object

Some utilities to populate beans, usually based on incoming request parameters. Requires three packages from the Apache Commons library: beanutils, collections, and logging. To obtain these packages, see http://jakarta.apache.org/commons/. Also, the book's source code archive (see http://www.coreservlets.com/) contains links to all URLs mentioned in the book, including to the specific sections of the Jakarta Commons package.

Note that this class is in the coreservlets.beans package, so must be installed in .../coreservlets/beans/.

Taken from Core Servlets and JavaServer Pages 2nd Edition from Prentice Hall and Sun Microsystems Press, http://www.coreservlets.com/. © 2003 Marty Hall; may be freely used or adapted.


Constructor Summary
BeanUtilities()
           
 
Method Summary
static void populateBean(java.lang.Object formBean, javax.servlet.http.HttpServletRequest request)
          Examines all of the request parameters to see if any match a bean property (i.e., a setXxx method) in the object.
static void populateBean(java.lang.Object bean, java.util.Map propertyMap)
          Populates a bean based on a Map: Map keys are the bean property names; Map values are the bean property values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanUtilities

public BeanUtilities()
Method Detail

populateBean

public static void populateBean(java.lang.Object formBean,
                                javax.servlet.http.HttpServletRequest request)
Examines all of the request parameters to see if any match a bean property (i.e., a setXxx method) in the object. If so, the request parameter value is passed to that method. If the method expects an int, Integer, double, Double, or any of the other primitive or wrapper types, parsing and conversion is done automatically. If the request parameter value is malformed (cannot be converted into the expected type), numeric properties are assigned zero and boolean properties are assigned false: no exception is thrown.


populateBean

public static void populateBean(java.lang.Object bean,
                                java.util.Map propertyMap)
Populates a bean based on a Map: Map keys are the bean property names; Map values are the bean property values. Type conversion is performed automatically as described above.