You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Asleson, Ryan" <as...@BIWORLDWIDE.com> on 2008/04/30 15:34:22 UTC

Struts 2 StrutsTypeConverter

 
Hello,
 
I am new to Struts 2, so please bear with me.
 
I am looking at implementing a custom StrutsTypeConverter.  I want it to
be a "global" converter (no just specific to an Action).  If I'm
understanding it correctly, to implement this I create an
xwork-conversion.properties file, and the format of this file is like
this:
 
com.domain.SomeCustomType=com.domain.SomeCustomTypeConverter
 
where SomeCustomTypeConverter implements StrutsTypeConverter.  First
question:  Is this correct?
 
Next question:  How well does this handle subclassing?  Here's what I
mean:
 
Suppose I have an abstract com.domain.SomeAbstractClass type that has
many subclasses, and it's these subclasses that I actually need to
convert.  I want to have an entry like this in
xwork-conversion.properties:
 
com.domain.SomeAbstractClass=com.domain.SomeAbstractClassConverter
 
Where SomeAbstractClassConverter is smart enough to convert any instance
of SomeAbstractClass.  For this to happen, the Class that is sent to the
convertFromString method must be the class of the actual
SomeAbstractClass subclass, not the SomeAbstractClass.  
 
Is this what happens at runtime?  Is the class that is sent to
convertFromString the actual class that is being converted, or the class
that is listed in the .properties file?  Will Struts2 use the
SomeAbstractClass converter for a subclass of SomeAbstractClass even if
it's not explicity defined in the .properties file?
 
Thank you!!
 
-Ryan
 
 
 
 

This e-mail message is being sent solely for use by the intended recipient(s) and may contain confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by phone or reply by e-mail, delete the original message and destroy all copies. Thank you.

Re: Struts 2 StrutsTypeConverter

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Asleson, Ryan wrote:
>  
> Hello,
>  
> I am new to Struts 2, so please bear with me.
>  
> I am looking at implementing a custom StrutsTypeConverter.  I want it to
> be a "global" converter (no just specific to an Action).  If I'm
> understanding it correctly, to implement this I create an
> xwork-conversion.properties file, and the format of this file is like
> this:
>  
> com.domain.SomeCustomType=com.domain.SomeCustomTypeConverter
>  
> where SomeCustomTypeConverter implements StrutsTypeConverter.  First
> question:  Is this correct?
>  
>   
Yes.  I added some new notes to that page today stating exactly that: 
http://struts.apache.org/2.x/docs/type-conversion.html

> Next question:  How well does this handle subclassing?  Here's what I
> mean:
>  
> Suppose I have an abstract com.domain.SomeAbstractClass type that has
> many subclasses, and it's these subclasses that I actually need to
> convert.  I want to have an entry like this in
> xwork-conversion.properties:
>  
> com.domain.SomeAbstractClass=com.domain.SomeAbstractClassConverter
>  
> Where SomeAbstractClassConverter is smart enough to convert any instance
> of SomeAbstractClass.  For this to happen, the Class that is sent to the
> convertFromString method must be the class of the actual
> SomeAbstractClass subclass, not the SomeAbstractClass.  
>  
> Is this what happens at runtime?  Is the class that is sent to
> convertFromString the actual class that is being converted, or the class
> that is listed in the .properties file?  Will Struts2 use the
> SomeAbstractClass converter for a subclass of SomeAbstractClass even if
> it's not explicity defined in the .properties file?
>  
> Thank you!!
>  
>   
Yes. From the javadoc:
 * Looks for converter mappings for the specified class, traversing up 
its class hierarchy and interfaces and adding
 * any additional mappings it may find.  Mappings lower in the hierarchy 
have priority over those higher in the
 * hierarcy.
 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org