Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.struts2.util
Class StrutsTypeConverter

    java.lang.Object
      ognl.DefaultTypeConverter
          org.apache.struts2.util.StrutsTypeConverter

All Implemented Interfaces:
  ognl.TypeConverter

    public 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.

Constructor Summary
`StrutsTypeConverter()`

Method Summary
`abstract Object` | `convertFromString(Map context, String[] values, Class toClass)` Converts one or more String values to the specified class.
`abstract String` | `convertToString(Map context, Object o)` Converts the specified object to a String.
`Object` | `convertValue(Map context, Object o, Class toClass)`
`protected Object` | `performFallbackConversion(Map context, Object o, Class toClass)` Hook to perform a fallback conversion if every default options failed.

Methods inherited from class ognl.DefaultTypeConverter
`convertValue`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### StrutsTypeConverter

    public StrutsTypeConverter()

Method Detail

### convertValue

    public Object convertValue(Map context,
                               Object o,
                               Class toClass)

  Overrides:
    `convertValue` in class `ognl.DefaultTypeConverter`

### performFallbackConversion

    protected Object performFallbackConversion(Map context,
                                               Object o,
                                               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.

  Parameters:
    `context` -
    `o` -
    `toClass` -
  Returns:
    The fallback conversion

### convertFromString

    public abstract Object convertFromString(Map context,
                                             String[] values,
                                             Class toClass)

  Converts one or more String values to the specified class.

  Parameters:
    `context` - the action context
    `values` - the String values to be converted, such as those submitted from an HTML form
    `toClass` - the class to convert to
  Returns:
    the converted object

### convertToString

    public abstract String convertToString(Map context,
                                           Object o)

  Converts the specified object to a String.

  Parameters:
    `context` - the action context
    `o` - the object to be converted
  Returns:
    the converted String

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.