use of org.webpieces.ctx.api.Flash in project webpieces by deanhiller.
the class FieldTag method createFieldData.
/**
*
*/
@SuppressWarnings("rawtypes")
private Map<String, Object> createFieldData(String fieldName2, Map<String, Object> pageArgs) {
Result result = reworkNameForArrayOnly(fieldName2, pageArgs);
String fieldName = result.fieldName;
Flash flash = Current.flash();
Validation validation = Current.validation();
Map<String, Object> field = new HashMap<String, Object>();
field.put("name", fieldName);
String id = makeValidHtml4Id(fieldName);
field.put("id", id);
String flashValue = flash.get(fieldName);
//different from fieldName only for Arrays
field.put("i18nKey", result.i18nName);
field.put("flash", flashValue);
field.put("error", validation.getError(fieldName));
field.put("errorClass", field.get("error") != null ? getErrorClass() : "");
String[] pieces = fieldName.split("\\.");
Object pageArgValue = null;
Object obj = pageArgs.get(pieces[0]);
if (pieces.length > 1) {
try {
String path = fieldName.substring(fieldName.indexOf(".") + 1);
pageArgValue = PropertyUtils.getProperty(obj, path);
} catch (Exception e) {
// if there is a problem reading the field we dont set any
// value
log.trace(() -> "exception", e);
}
} else {
//for method parameters not fields in the bean like above
pageArgValue = obj;
}
field.put("value", pageArgValue);
String valAsStr = null;
if (pageArgValue instanceof Collection) {
//For multiple select html OptionTag to work, this was needed
valAsStr = convert((Collection) pageArgValue);
} else {
valAsStr = converter.convert(pageArgValue);
}
field.put("flashOrValue", preferFirst(flashValue, valAsStr));
field.put("valueOrFlash", preferFirst(valAsStr, flashValue));
return field;
}
Aggregations