You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ramanathan RV <ra...@gmail.com> on 2008/04/15 12:29:14 UTC
Type conversion with enum elements
Hello,
I wish to display/read value that belongs to an enumerated type. Struts
seems to handle Class and Enum differently. For instance,
*xwork-conversion*
com.company.utils.Constants.EducationalQualification=com.company.ui.utils.EducationalQualificationConverter
java.util.Date=com.loandukaan.ui.utils.DateConverter
For the date parameter, the converter gets invoked. Whereas, for the type
EducationalQualification, the converter doesnt get invoked and the set
method in the form bean fails. Any thoughts?
--
Thanks
Ram
Re: Type conversion with enum elements
Posted by Ralf Fischer <th...@googlemail.com>.
Hi
On Tue, Apr 15, 2008 at 12:29 PM, Ramanathan RV <ra...@gmail.com> wrote:
> Hello,
>
> I wish to display/read value that belongs to an enumerated type. Struts
> seems to handle Class and Enum differently. For instance,
>
> *xwork-conversion*
> com.company.utils.Constants.EducationalQualification=com.company.ui.utils.EducationalQualificationConverter
> java.util.Date=com.loandukaan.ui.utils.DateConverter
>
> For the date parameter, the converter gets invoked. Whereas, for the type
> EducationalQualification, the converter doesnt get invoked and the set
> method in the form bean fails. Any thoughts?
Actually this is xwork-behaviour. It already provides the class
com.opensymphony.xwork2.util.EnumTypeConverter[1], which you can
simply use to convert your Enum:
xwork-conversion.properties:
foo.bar.MyEnumeration = com.opensymphony.xwork2.util.EnumTypeConverter
If you don't like the default behaviour using the Enum name() as
representation in the page, you can always write your own type
converter[2].
Cheers,
-Ralf
[1] http://struts.apache.org/2.x/struts2-core/apidocs/com/opensymphony/xwork2/util/EnumTypeConverter.html
[2] http://struts.apache.org/2.0.11.1/docs/type-conversion.html
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Type conversion with enum elements
Posted by Giovanni Azua <gi...@imc.nl>.
hi,
A simple workaround would be defining the bean property as String type
rather than as the actual enum.
Then use the two enum type built in operations "name()" and "valueOf()"
to implement the getter and setter respectively.
If there is actually an elegant way to do it, I would also be interested
to know.
regards,
Giovanni
Ramanathan RV wrote:
> Hello,
>
> I wish to display/read value that belongs to an enumerated type. Struts
> seems to handle Class and Enum differently. For instance,
>
> *xwork-conversion*
> com.company.utils.Constants.EducationalQualification=com.company.ui.utils.EducationalQualificationConverter
> java.util.Date=com.loandukaan.ui.utils.DateConverter
>
> For the date parameter, the converter gets invoked. Whereas, for the type
> EducationalQualification, the converter doesnt get invoked and the set
> method in the form bean fails. Any thoughts?
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org