use of org.apache.wicket.util.convert.IConverter in project wicket by apache.
the class Component method getDefaultModelObjectAsString.
/**
* Gets a model object as a string. Depending on the "escape model strings" flag of the
* component, the string is either HTML escaped or not. "HTML escaped" meaning that only HTML
* sensitive chars are escaped but not all none-ascii chars. Proper HTML encoding should be used
* instead. In case you really need a fully escaped model string you may call
* {@link Strings#escapeMarkup(CharSequence, boolean, boolean)} on the model string returned.
*
* @see Strings#escapeMarkup(CharSequence, boolean, boolean)
* @see #getEscapeModelStrings()
*
* @param modelObject
* Model object to convert to string
* @return The string
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public final String getDefaultModelObjectAsString(final Object modelObject) {
if (modelObject != null) {
// Get converter
final Class<?> objectClass = modelObject.getClass();
final IConverter converter = getConverter(objectClass);
// Model string from property
final String modelString = converter.convertToString(modelObject, getLocale());
if (modelString != null) {
// If we should escape the markup
if (getFlag(FLAG_ESCAPE_MODEL_STRINGS)) {
// Escape HTML sensitive characters only. Not all none-ascii chars
return Strings.escapeMarkup(modelString, false, false).toString();
}
return modelString;
}
}
return "";
}
Aggregations