views:

591

answers:

2

without using any big web framework (just servlets), do you know a ready to use small library that can populate my bean properties from the params of an http request?

+2  A: 

The easiest one is probably the * -version of <jsp:setProperty name="mybean" properties="*" >

From http://java.sun.com/products/jsp/tags/11/syntaxref11.fm13.html :

"Stores all of the values the user enters in the viewable JSP page (called request parameters) in matching Bean properties. The names of the properties in the Bean must match the names of the request parameters, which are usually the elements of an HTML form. A Bean property is usually defined by a variable declaration with matching getter and setter methods"

Thorbjørn Ravn Andersen
+3  A: 

You could take a look at Commons Beanutils, it has a whole bunch of methods for populating beans (including nested beans):

http://commons.apache.org/beanutils/

The method, in particular, that you want to look at is populate in BeanUtilsBean:

public void populate(Object bean,
                     Map properties)

More info here:

http://commons.apache.org/beanutils/api/org/apache/commons/beanutils/BeanUtilsBean.html#populate%28java.lang.Object,%20java.util.Map%29

Jon