You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by senderj <se...@hotmail.com> on 2009/09/23 10:14:44 UTC

[Struts 1.3] first time use custom converter not working

I have a class Stk with property warType of type enum WarrType

    public enum WarrType {
        NONE, CALL, PUT; }

I have in my struts config

<form-bean name="MyForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="warType" type="java.lang.String"/>

and in my Action

   MyConverter mc = new MyConverter();
   ConvertUtils.register(mc, WarrType.class);
   PropertyUtils.copyProperties(stk, form);
   ...... 
and embedded in the Action class

   public class MyConverter implements Converter {
   @Override
   public WarrType convert(Class c, Object s) {
        WarrType result = null;
         System.out.println("I am running");
         if (s.equals("NONE")) result = WarrType.NONE;
        return result; ....

The problem is the convert() never executed. the copyProperties failed with
"...had String ... expect WarrType...". Any idea why?

-- 
View this message in context: http://www.nabble.com/-Struts-1.3--first-time-use-custom-converter-not-working-tp25531027p25531027.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [Struts 1.3] first time use custom converter not working

Posted by Arthur Neves <ar...@gmail.com>.
HI,

You must create your property as a WarrType.
<form-property name="warType" type="foo.bar.WarrType"/>

Then your converter will be call.


On Sat, Oct 3, 2009 at 10:21 PM, Paul Benedict <pb...@apache.org> wrote:

> Ever solve this? Are you sure you registered your converter properly?
>
> Paul
>
> On Wed, Sep 23, 2009 at 3:14 AM, senderj <se...@hotmail.com> wrote:
> >
> > I have a class Stk with property warType of type enum WarrType
> >
> >    public enum WarrType {
> >        NONE, CALL, PUT; }
> >
> > I have in my struts config
> >
> > <form-bean name="MyForm"
> > type="org.apache.struts.validator.DynaValidatorForm">
> > <form-property name="warType" type="java.lang.String"/>
> >
> > and in my Action
> >
> >   MyConverter mc = new MyConverter();
> >   ConvertUtils.register(mc, WarrType.class);
> >   PropertyUtils.copyProperties(stk, form);
> >   ......
> > and embedded in the Action class
> >
> >   public class MyConverter implements Converter {
> >   @Override
> >   public WarrType convert(Class c, Object s) {
> >        WarrType result = null;
> >         System.out.println("I am running");
> >         if (s.equals("NONE")) result = WarrType.NONE;
> >        return result; ....
> >
> > The problem is the convert() never executed. the copyProperties failed
> with
> > "...had String ... expect WarrType...". Any idea why?
> >
> > --
> > View this message in context:
> http://www.nabble.com/-Struts-1.3--first-time-use-custom-converter-not-working-tp25531027p25531027.html
> > Sent from the Struts - User mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [Struts 1.3] first time use custom converter not working

Posted by Paul Benedict <pb...@apache.org>.
Ever solve this? Are you sure you registered your converter properly?

Paul

On Wed, Sep 23, 2009 at 3:14 AM, senderj <se...@hotmail.com> wrote:
>
> I have a class Stk with property warType of type enum WarrType
>
>    public enum WarrType {
>        NONE, CALL, PUT; }
>
> I have in my struts config
>
> <form-bean name="MyForm"
> type="org.apache.struts.validator.DynaValidatorForm">
> <form-property name="warType" type="java.lang.String"/>
>
> and in my Action
>
>   MyConverter mc = new MyConverter();
>   ConvertUtils.register(mc, WarrType.class);
>   PropertyUtils.copyProperties(stk, form);
>   ......
> and embedded in the Action class
>
>   public class MyConverter implements Converter {
>   @Override
>   public WarrType convert(Class c, Object s) {
>        WarrType result = null;
>         System.out.println("I am running");
>         if (s.equals("NONE")) result = WarrType.NONE;
>        return result; ....
>
> The problem is the convert() never executed. the copyProperties failed with
> "...had String ... expect WarrType...". Any idea why?
>
> --
> View this message in context: http://www.nabble.com/-Struts-1.3--first-time-use-custom-converter-not-working-tp25531027p25531027.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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