|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectwicket.util.convert.LocalizableAdapter
wicket.util.convert.SimpleConverterAdapter
public abstract class SimpleConverterAdapter
Adapter class to simplify implementing custom IConverters. If the
requested type to convert to is a string type (or more precice, assignable
from CharSequence), this converter will delegate type conversion to
toString(Object). Otherwise, it will delegate type conversion to
toObject(String) using the object's Object.toString() value
to convert it to a string first (or passing in null in case the value is
null).
Note, this class is specifically meant for providing custom converters per
component by overriding Component.getConverter(). It is less usefull
for application scoped converters; registering ITypeConverters with
an instance of Converter is a better choice for that.
WARNING. Due to a current limitation as a result of how
IConverter works, classes that extend this adapter will not be much
use with string values. If you want to use a custom converter for string
values, consider wrapping the values in another class so that conversion will
be triggered. See the form input example of wicket-examples for how this can
be done.
An example of the use of this class is the following:
add(new TextField("urlProperty", URL.class)
{
public IConverter getConverter()
{
return new SimpleConverterAdapter()
{
public String toString(Object value)
{
return value != null ? value.toString() : null;
}
public Object toObject(String value)
{
try
{
return new URL(value.toString());
}
catch (MalformedURLException e)
{
throw new ConversionException("'" + value + "' is not a valid URL");
}
}
};
}
});
| Constructor Summary | |
|---|---|
SimpleConverterAdapter()
|
|
| Method Summary | |
|---|---|
java.lang.Object |
convert(java.lang.Object value,
java.lang.Class c)
If class c is a string type (or more precise, assignable from CharSequence), this method will delegate type conversion to
toString(Object). |
abstract java.lang.Object |
toObject(java.lang.String value)
Convert the given string to an object of choice. |
abstract java.lang.String |
toString(java.lang.Object value)
Convert the given value to a string. |
| Methods inherited from class wicket.util.convert.LocalizableAdapter |
|---|
getLocale, setLocale |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface wicket.util.convert.ILocalizable |
|---|
getLocale, setLocale |
| Constructor Detail |
|---|
public SimpleConverterAdapter()
| Method Detail |
|---|
public final java.lang.Object convert(java.lang.Object value,
java.lang.Class c)
CharSequence), this method will delegate type conversion to
toString(Object). Otherwise, it will delegate type conversion
to toObject(String) using the object's Object.toString()
value to convert it to a string first (or passing in null in case the
value is null).
convert in interface IConvertervalue - The value to convertc - The class of object to convert to
IConverter.convert(java.lang.Object,
java.lang.Class)public abstract java.lang.String toString(java.lang.Object value)
value - The value to convert, may be null
public abstract java.lang.Object toObject(java.lang.String value)
value - The string to convert, may be null
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||