layout: default title: TypeConversion Annotation parent: title: Annotations url: annotations.html

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

  • Application wide conversion:

    The conversion rules will be assembled within the struts-conversion.properties or xwork-conversion.properties (deprecated) file within the classpath root. Set type to: type = ConversionType.APPLICATION

Usage

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

Parameters

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)
   @StrutsParameter
   public void setConvertInt( String convertInt ) {
       this.convertInt = convertInt;
   }

   @TypeConversion(converterClass = XWorkBasicConverter.class)
   @StrutsParameter
   public void setConvertDouble( String convertDouble ) {
       this.convertDouble = convertDouble;
   }

   @TypeConversion(rule = ConversionRule.COLLECTION, converterClass = String.class)
   @StrutsParameter
   public void setUsers( List users ) {
       this.users = users;
   }

   @TypeConversion(rule = ConversionRule.MAP, converterClass = BigInteger.class)
   @StrutsParameter
   public void setKeyValues( HashMap keyValues ) {
       this.keyValues = keyValues;
   }

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