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

## com.opensymphony.xwork2.conversion.impl
Class EnumTypeConverter

    java.lang.Object
      com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter
          com.opensymphony.xwork2.conversion.impl.EnumTypeConverter

All Implemented Interfaces:
  TypeConverter

Deprecated. Since Struts 2.1.0 as enum support is now built into XWork

    @Deprecated
    public class EnumTypeConverter

extends DefaultTypeConverter

`EnumTypeConverter` This class converts java 5 enums to String and from String[] to enum.

One of Java 5's improvements is providing enumeration facility. Up to now, there existed no enumerations. The only way to simulate was the so-called int Enum pattern: {code} public static final int SEASON_WINTER = 0; public static final int SEASON_SPRING = 1; public static final int SEASON_SUMMER = 2; public static final int SEASON_FALL = 3; {code}

Java 5.0 now provides the following construct: {code} public static enum Season { WINTER, SPRING, SUMMER, FALL }; {code} h3. Implementing Java 5 Enumeration Type Conversion

1. myAction-conversion.properties*

Place a myAction-conversion.properties-file in the path of your Action. Add the following entry to the properties-file: {code} nameOfYourField=fullyClassifiedNameOfYourConverter {code}

2. myAction.java* Your action contains the _enumeration_: {code} public enum Criticality {DEBUG, INFO, WARNING, ERROR, FATAL} {code} * Your action contains the _private field_: {code} private myEnum myFieldForEnum; {code} Your action contains _getters and setters_ for your field: {code} public myEnum getCriticality() { return myFieldForEnum; } public void setCriticality(myEnum myFieldForEnum) { this.myFieldForEnum= myFieldForEnum; } {code}

3. JSP*

In your jsp you can access an enumeration value just normal by using the known -Tag: {code} {code}

Version:
  $Id: EnumTypeConverter.java 894090 2009-12-27 18:18:29Z martinc $
Author:
  Tamara Cattivelli, Rainer Hermanns

Field Summary

Fields inherited from interface com.opensymphony.xwork2.conversion.TypeConverter
`NO_CONVERSION_POSSIBLE, TYPE_CONVERTER_CONTEXT_KEY`

Constructor Summary
`EnumTypeConverter()` Deprecated.

Method Summary
`java.lang.Enum` | `convertFromString(java.lang.String value, java.lang.Class toClass)` Deprecated. Converts one or more String values to the specified class.
`java.lang.Object` | `convertValue(java.util.Map<java.lang.String,java.lang.Object> context, java.lang.Object o, java.lang.Class toClass)` Deprecated. Converts the given object to a given type.

Methods inherited from class com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter
`bigDecValue, bigIntValue, booleanValue, convertValue, convertValue, doubleValue, enumValue, getTypeConverter, longValue, stringValue, stringValue`

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

Constructor Detail

### EnumTypeConverter

    public EnumTypeConverter()

  Deprecated.

Method Detail

### convertValue

    public java.lang.Object convertValue(java.util.Map<java.lang.String,java.lang.Object> context,
                                         java.lang.Object o,
                                         java.lang.Class toClass)

  Deprecated.
  Converts the given object to a given type. How this is to be done is implemented in toClass. The OGNL context, o and toClass are given. This method should be able to handle conversion in general without any context or object specified.

  Overrides:
    `convertValue` in class `DefaultTypeConverter`
  Parameters:
    `context` - - OGNL context under which the conversion is being done
    `o` - - the object to be converted
    `toClass` - - the class that contains the code to convert to enumeration
  Returns:
    Converted value of type declared in toClass or TypeConverter.NoConversionPossible to indicate that the conversion was not possible.

### convertFromString

    public java.lang.Enum convertFromString(java.lang.String value,
                                            java.lang.Class toClass)

  Deprecated.
  Converts one or more String values to the specified class.

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

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-2011 Apache Software Foundation. All Rights Reserved.