StrutsTypeConverterpublic abstract class StrutsTypeConverter extends ognl.DefaultTypeConverter
Base class for type converters used in Struts. This class provides two abstract methods that are used to convert
both to and from strings -- the critical functionality that is core to Struts's type coversion system.
Type converters do not have to use this class. It is merely a helper base class, although it is recommended that
you use this class as it provides the common type conversion contract required for all web-based type conversion.
There's a hook (fall back method) called performFallbackConversion of which
could be used to perform some fallback conversion if convertValue method of this
failed. By default it just ask its super class (Ognl's DefaultTypeConverter) to do the conversion.
To allow the framework to recognize that a conversion error has occurred, throw an XWorkException or
preferable a TypeConversionException.
|
Methods Summary |
---|
public abstract java.lang.Object | convertFromString(java.util.Map context, java.lang.String[] values, java.lang.Class toClass)Converts one or more String values to the specified class.
| public abstract java.lang.String | convertToString(java.util.Map context, java.lang.Object o)Converts the specified object to a String.
| public java.lang.Object | convertValue(java.util.Map context, java.lang.Object o, java.lang.Class toClass)
if (toClass.equals(String.class)) {
return convertToString(context, o);
} else if (o instanceof String[]) {
return convertFromString(context, (String[]) o, toClass);
} else if (o instanceof String) {
return convertFromString(context, new String[]{(String) o}, toClass);
} else {
return performFallbackConversion(context, o, toClass);
}
| protected java.lang.Object | performFallbackConversion(java.util.Map context, java.lang.Object o, java.lang.Class toClass)Hook to perform a fallback conversion if every default options failed. By default
this will ask Ognl's DefaultTypeConverter (of which this class extends) to
perform the conversion.
return super.convertValue(context, o, toClass);
|
|