Dashboard > WebWork > ... > J2SE 5 Support > TypeConversion Annotation
  WebWork Log In View a printable version of the current page.  
  TypeConversion Annotation
Added by Rainer Hermanns, last edited by Rainer Hermanns on Apr 13, 2007  (view change)
Labels: 
(None)

TypeConversion Annotation

This annotation is used for class and application wide conversion rules.

Class wide conversion:
The conversion rules will be assembled in a file called XXXAction-conversion.properties within the same package as the related action class. Set type to: type = ConversionType.CLASS

Allication wide conversion:
The conversion rules will be assembled within the xwork-conversion.properties file within the classpath root. Set type to: type = ConversionType.APPLICATION

Usage

The TypeConversion annotation can be applied at property and method level.

Parameters

Parameter Required Default Description
key no The annotated property/key name The optional property name mostly used within TYPE level annotations.
type no ConversionType.CLASS Enum value of ConversionType. Determines whether the conversion should be applied at application or class level.
rule no ConversionRule.PROPERTY Enum value of ConversionRule. The ConversionRule can be a property, a Collection or a Map.
converter either this or value   The class name of the TypeConverter to be used as converter.
value either converter or this   The value to set for ConversionRule.KEY_PROPERTY.

Examples

@Conversion()
public class ConversionAction implements Action {

  private String convertInt;

  private String convertDouble;
  private List users = null;

  private HashMap keyValues = null;

  @TypeConversion(type = ConversionType.APPLICATION, converter = "com.opensymphony.xwork.util.XWorkBasicConverter")
  public void setConvertInt( String convertInt ) {
      this.convertInt = convertInt;
  }

  @TypeConversion(converter = "com.opensymphony.xwork.util.XWorkBasicConverter")
  public void setConvertDouble( String convertDouble ) {
      this.convertDouble = convertDouble;
  }

  @TypeConversion(rule = ConversionRule.COLLECTION, converter = "java.util.String")
  public void setUsers( List users ) {
      this.users = users;
  }

  @TypeConversion(rule = ConversionRule.MAP, converter = "java.math.BigInteger")
  public void setKeyValues( HashMap keyValues ) {
      this.keyValues = keyValues;
  }

  @TypeConversion(type = ConversionType.APPLICATION, property = "java.util.Date", converter = "com.opensymphony.xwork.util.XWorkBasicConverter")
  public String execute() throws Exception {
      return SUCCESS;
  }
}

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request - Contact Administrators