if (fieldList == null) {
throw new IllegalArgumentException("Null fieldList parameter");
}
if (fieldList.isEmpty()) {
LogService logService = ClickUtils.getLogService();
if (logService.isDebugEnabled()) {
String containerClassName =
ClassUtils.getShortClassName(container.getClass());
logService.debug(" " + containerClassName
+ " has no fields to copy from");
}
//Exit early.
return;
}
String objectClassname = object.getClass().getName();
objectClassname =
objectClassname.substring(objectClassname.lastIndexOf(".") + 1);
// If the given object is a map, its key/value pair is populated from
// the fields name/value pair.
if (object instanceof Map) {
copyFieldsToMap(fieldList, (Map) object);
// Exit after populating the map.
return;
}
LogService logService = ClickUtils.getLogService();
Set<String> properties = getObjectPropertyNames(object);
Map ognlContext = new HashMap();
for (Field field : fieldList) {
// Ignore disabled field as their values are not submitted in HTML
// forms
if (field.isDisabled()) {
continue;
}
if (!hasMatchingProperty(field, properties)) {
continue;
}
String fieldName = field.getName();
ensureObjectPathNotNull(object, fieldName);
try {
PropertyUtils.setValueOgnl(object, fieldName, field.getValueObject(), ognlContext);
if (logService.isDebugEnabled()) {
String containerClassName =
ClassUtils.getShortClassName(container.getClass());
String msg = " " + containerClassName + " -> "
+ objectClassname + "." + fieldName + " : "
+ field.getValueObject();
logService.debug(msg);
}
} catch (Exception e) {
String msg =
"Error incurred invoking " + objectClassname + "."
+ fieldName + " with " + field.getValueObject()
+ " error: " + e.toString();
logService.debug(msg);
}
}
}