You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alec Bau <Al...@msdw.com> on 2000/07/18 02:50:08 UTC
Bug in BeanUtils.populate ?
To fight problem with image buttons (reported earlier) I was trying to use form suffix
(ActionMapping.getFormSuffix) support to map <name>.x/y parameters. I think there's a
bug in BeanUtils.populate(bean, prefix, suffix, request) method that's called from
ActionServlet.processActionForm method.
Here's the abstract from BeanUtils.populate:
// Build a list of relevant request parameters from this request
Hashtable properties = new Hashtable();
Enumeration names = request.getParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
if (prefix != null) {
if (!name.startsWith(prefix))
continue;
name = name.substring(0, prefix.length());
}
if (suffix != null) {
if (!name.endsWith(suffix))
continue;
name = name.substring(0, name.length() - suffix.length());
}
properties.put(name, request.getParameterValues(name));
}
For non null suffix or prefix last line stores null as a value since request parameter
value couldn't be found for the name that's already stripped of prefix and/or suffix.
Later because of that BeanUtils.populate(bean, properties) skips parameter processing
altogether. Perhaps loop body should be changed to something like that:
String name = (String) names.nextElement();
String striped = name;
if (prefix != null) {
if (!name.startsWith(prefix))
continue;
striped = name.substring(0, prefix.length());
}
if (suffix != null) {
if (!name.endsWith(suffix))
continue;
striped = name.substring(0, name.length() - suffix.length());
}
properties.put(striped, request.getParameterValues(name));
Thanks.