alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  
* <td>no * <td>The annotated property/key name * <td>The optional property name mostly used within TYPE level annotations. * </tr> * <tr> * <td>type * <td>no * <td>ConversionType.CLASS * <td>Enum value of ConversionType. Determines whether the conversion should be applied at application or class level. * </tr> * <tr> * <td>rule * <td>no * <td>ConversionRule.PROPERTY * <td>Enum value of ConversionRule. The ConversionRule can be a property, a Collection or a Map. * </tr> * <tr> * <td>converter * <td>either this or value * <td>  * <td>The class name of the TypeConverter to be used as converter. * </tr> * <tr> * <td>value * <td>either converter or this * <td>  * <td>The value to set for ConversionRule.KEY_PROPERTY. * </tr> * </tbody> * </table> * * <!-- END SNIPPET: parameters --> * * <p/> Example code: * * <pre> * <!-- START SNIPPET: example --> * @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.xwork2.util.XWorkBasicConverter") * public void setConvertInt( String convertInt ) { * this.convertInt = convertInt; * } * * @TypeConversion(converter = "com.opensymphony.xwork2.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.xwork2.util.XWorkBasicConverter") * public String execute() throws Exception { * return SUCCESS; * } * } * <!-- END SNIPPET: example --> * </pre> * * @author Rainer Hermanns * @version $Id: TypeConversion.java 894090 2009-12-27 18:18:29Z martinc $ */ @Target({ ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface TypeConversion { /** * The optional key name used within TYPE level annotations. * Defaults to the property name. */ String key() default ""; /** * The ConversionType can be either APPLICATION or CLASS. * Defaults to CLASS. * * Note: If you use ConversionType.APPLICATION, you can not set a value! */ ConversionType type() default ConversionType.CLASS; /** * The ConversionRule can be a PROPERTY, KEY, KEY_PROPERTY, ELEMENT, COLLECTION (deprecated) or a MAP. * Note: Collection and Map vonversion rules can be determined via com.opensymphony.xwork2.util.DefaultObjectTypeDeterminer. * * @see com.opensymphony.xwork2.conversion.impl.DefaultObjectTypeDeterminer */ ConversionRule rule() default ConversionRule.PROPERTY; /** * The class of the TypeConverter to be used as converter. * * Note: This can not be used with ConversionRule.KEY_PROPERTY! */ String converter() default ""; /** * If used with ConversionRule.KEY_PROPERTY specify a value here! * * Note: If you use ConversionType.APPLICATION, you can not set a value! */ String value() default ""; }

Other Struts examples (source code examples)

Here is a short list of links related to this Struts TypeConversion.java source code file:

Struts example source code file (TypeConversion.java)

This example Struts source code file (TypeConversion.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Struts tags/keywords

annotation, conversionrule, conversiontype, conversiontype, string, string, target, target, typeconversion, typeconversion

The Struts TypeConversion.java source code

/*
 * Copyright 2002-2006,2009 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.opensymphony.xwork2.conversion.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * <!-- START SNIPPET: description -->
 * <p/>This annotation is used for class and application wide conversion rules.
 * <p>
 * Class wide conversion:<br/>
 * The conversion rules will be assembled in a file called <code>XXXAction-conversion.properties
 * within the same package as the related action class.
 * Set type to: <code>type = ConversionType.CLASS
 * </p>
 * <p>
 * Allication wide conversion:<br/>
 * The conversion rules will be assembled within the <code>xwork-conversion.properties file within the classpath root.
 * Set type to: <code>type = ConversionType.APPLICATION
 * <p/>
 * <!-- END SNIPPET: description -->
 *
 * <p/> Annotation usage:
 *
 * <!-- START SNIPPET: usage -->
 * The TypeConversion annotation can be applied at property and method level.
 * <!-- END SNIPPET: usage -->
 *
 * <p/> Annotation parameters:
 *
 * <!-- START SNIPPET: parameters -->
 * <table>
 * <thead>
 * <tr>
 * <th>Parameter
 * <th>Required
 * <th>Default
 * <th>Description
 * </tr>
 * </thead>
 * <tbody>
 * <tr>
 * <td>key
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.