Eric,
This is how the Apache Jasper engine does it with JSP's. I am
sure you could use it in your servlet too .. with some modifications. The
same can also be found in the source for the
"org.apache.jasper.runtime.JspRuntimeLibrary" class.
regards
Pramod Nair
public static void introspect(Object bean, ServletRequest request)
throws JasperException
{
Enumeration e = request.getParameterNames();
while ( e.hasMoreElements() ) {
String name = (String) e.nextElement();
String value = request.getParameter(name);
introspecthelper(bean, name, value, request, name, true);
}
}
// __end introspectMethod
// __begin introspecthelperMethod
public static void introspecthelper(Object bean, String prop,
String value, ServletRequest request,
String param, boolean ignoreMethodNF)
throws JasperException
{
java.lang.reflect.Method method = null;
Class type = null;
try {
java.beans.BeanInfo info
= java.beans.Introspector.getBeanInfo(bean.getClass());
if ( info != null ) {
java.beans.PropertyDescriptor pd[]
= info.getPropertyDescriptors();
for (int i = 0 ; i < pd.length ; i++) {
if ( pd[i].getName().equals(prop) ) {
method = pd[i].getWriteMethod();
type = pd[i].getPropertyType();
break;
}
}
}
if ( method != null ) {
if (type.isArray()) {
if (request == null) {
throw new JasperException(Constants.getString(
"jsp.error.beans.setproperty.noindexset",
new Object[] {}));
};
Class t = type.getComponentType();
String[] values = request.getParameterValues(param);
file://XXX Please check.
if(values == null) return;
if(t.equals(String.class)) {
method.invoke(bean, new Object[] { values });
} else {
Object tmpval = null;
createTypedArray (bean, method, values, t);
}
} else {
if(value == null || (param != null && value.equals(""))) return;
Object oval = convert(value, type);
if ( oval != null )
method.invoke(bean, new Object[] { oval });
}
}
} catch (Exception ex) {
throw new JasperException (ex);
}
if (!ignoreMethodNF && (method == null)) {
if (type == null) {
throw new JasperException(Constants.getString(
"jsp.error.beans.noproperty",
new Object[] {prop, bean.getClass().getName()}));
} else {
throw new JasperException(Constants.getString(
"jsp.error.beans.nomethod.setproperty",
new Object[] {prop, bean.getClass().getName()}));
}
}
}
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html