Column[] keyColumns = record.getKeyColumns();
// Pull all field values
int fieldCount = record.getFieldCount();
for (int i = 0; i < fieldCount; i++)
{
Column col = record.getColumn(i);
// Check wether it is a key column
if (ObjectUtils.contains(keyColumns, col))
continue;
// Get the value from the input control
Object value = null;
String field = getRequestFieldName(col);
InputControl control = null;
if (record.isFieldReadOnly(col)==false)
control = InputControlManager.getControl(col.getControlType());
// Get Value from Control first
if (control!=null && (value=control.getFieldValue(field, action, locale, col))!=null)
{ // Check for Error
if (value instanceof InputControl.FieldValueError)
{
InputControl.FieldValueError fieldError = (InputControl.FieldValueError)value;
// Error
String errorValue = fieldError.getValue();
addFieldError(field, col, fieldError, errorValue);
setRecordFieldValue(i, errorValue, false);
valid = false;
continue;
}
// Check Value
if (value.equals(InputControl.NULL_VALUE) && col.isRequired())
{ // Oops, columns is required
InputControl.FieldValueError fieldError = new InputControl.FieldValueError(FieldErrors.InputValueRequired, null, "");
addFieldError(field, col, fieldError, value);
valid = false;
continue;
}
// set field value now
if (log.isInfoEnabled())
log.info("SetUpdateFields: setting field '" + col.getName() + "' to " + String.valueOf(value));
if (!setRecordFieldValue(i, value, true))
{ // Force to set field value
if (record instanceof ErrorInfo)
addFieldError(field, col, (ErrorInfo)record, value);
else
addFieldError(field, col, new ActionError(FieldErrors.InputInvalidValue), value);
// set Value
setRecordFieldValue(i, value, false);
valid = false;
}
}
else if ((value=action.getRequestParam(field + "!"))!=null)
{ // hidden value
if (col.getDataType()==DataType.DATE || col.getDataType()==DataType.DATETIME)
{ // Special for Dates and timestamps
if (value.equals(sysdate)==false)
{ // Parse Date Time
String format = (col.getDataType()==DataType.DATE) ? "yyyy-MM-dd" : "yyyy-MM-dd HH:mm:ss.S";
SimpleDateFormat sdf = new SimpleDateFormat(format);
try {
value = sdf.parseObject(value.toString());
} catch(ParseException e) {
log.error("Failed to parse date for record", e);
continue;
}
}
}
// Set Value
if (log.isInfoEnabled())
log.info("SetUpdateFields: directly setting field '" + col.getName() + "' to " + String.valueOf(value));
// Has Value changed?
if (ObjectUtils.compareEqual(record.getValue(i), value)==false)
{ // Modify Value
setRecordFieldValue(i, value, false);
}