in empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java [260:324]
protected String formatValue(Object value, ValueInfo vi, boolean escapeHTML)
{
// Lookup and Print value
Options options = vi.getOptions();
if (options != null && !options.isEmpty() && !hasFormatOption(vi, "nolookup"))
{ // Check for Options
String text = options.get(value);
if (StringUtils.isNotEmpty(text))
return vi.getText(text);
// Error
if (value!=null)
TextInputControl.log.error("The element '" + String.valueOf(value) + "' is not part of the supplied option list.");
}
// Check Value
if (value == null)
{ // Try to use default value
Object nullValue = getFormatOption(vi, InputControl.FORMAT_NULL, InputControl.FORMAT_NULL_ATTRIBUTE);
if (nullValue != null)
return formatValue(nullValue, vi);
// Empty String
return "";
}
// Format Value
Column column = vi.getColumn();
DataType dataType = getValueType(value, (column != null) ? column.getDataType() : DataType.UNKNOWN);
if (dataType.isText() || dataType == DataType.UNKNOWN)
{ // String
String s = String.valueOf(value);
if (hasFormatOption(vi, "noencode"))
return s;
// Encoded text
if (escapeHTML)
s = escapeHTML(s);
return s;
}
if (dataType == DataType.INTEGER || dataType == DataType.AUTOINC)
{ // Integer
NumberFormat nf = NumberFormat.getIntegerInstance(vi.getLocale());
nf.setGroupingUsed(false);
return nf.format(value);
}
if (dataType == DataType.DECIMAL || dataType == DataType.FLOAT)
{ // Dezimal oder Double
NumberFormat nf = getNumberFormat(dataType, vi.getLocale(), column);
return nf.format(value);
}
if (dataType == DataType.DATE || dataType == DataType.DATETIME || dataType == DataType.TIMESTAMP)
{ // Date or DateTime
if (dataType!= DataType.DATE && hasFormatOption(vi, "notime"))
dataType = DataType.DATE;
// Now format the date according to the user's locale
DateFormat df = getDateFormat(dataType, vi, column);
return df.format(value);
}
/*
* if (dataType == DBDataType.BOOL) {
* }
*/
// Convert to String
if (escapeHTML)
{
return escapeHTML(String.valueOf(value));
}
return String.valueOf(value);
}