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 12:16:57 UTC

[Struts 1.3] converter converts but not set property

I wrote a converter to convert a enum for BeanUtils.copyProperties().  I have
this in my struts config:

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

Here is my converters (embedded class in my Action)

    public class MyConverter1 implements Converter {
        @Override
        public WarrType convert(Class c, Object s) {
            Object result = null;
            String ss = (String) s;
            if (c.getSimpleName().equals("WarrType")) {
                System.out.println(ss);
                if (ss.equals("NONE")) result = WarrType.NONE;
                if (ss.equals("CALL"))  result = WarrType.CALL;
                if (ss.equals("PUT")) result = WarrType.PUT;
            }
            return (WarrType) result;
        }
    }

and here is the code in my Action:

        MyConverter1 mc1 = new MyConverter1();
        ConvertUtils.register(mc1, WarrType.class);
        BeanUtils.copyProperties(stk, form);

I've ensured both Stk and form have the same name "warType". But the
copyProperties() takes care of all other properties, except the warType! I
have another converter for a date properties coded in similar way and it
works. Only this warType doesn't. I have checked the convert() method in
MyConverter in debug mode and it can convert correctly. But the stk.warType
was not set (although its setWarType() was run with correct parm and
output).

But if I add this code after the copyProperties() at the above, then it
works
        BeanUtils.copyProperty(stk, "warType",
PropertyUtils.getSimpleProperty(form, "warType"));

Any idea why?

-- 
View this message in context: http://www.nabble.com/-Struts-1.3--converter-converts-but-not-set-property-tp25531070p25531070.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] converter converts but not set property

Posted by senderj <se...@hotmail.com>.
Thanks for the reply. The warType is WarrType. The convert() method executed.
It has correct input parm and output return (I've used debugger to check
it). The copyProperties() just doesn't copy it after the convert(). That's
why I have to add copyProperty() to explicitly copy "warType".


Arthur Neves wrote:
> 
> BeansUtils just call your converter, if your form bean property "warType",
> will be a 'WarrType' .
> 
> On Wed, Sep 23, 2009 at 7:16 AM, senderj <se...@hotmail.com> wrote:
> 
>>
>> I wrote a converter to convert a enum for BeanUtils.copyProperties().  I
>> have
>> this in my struts config:
>>
>> <form-bean name="MyForm"
>> type="org.apache.struts.validator.DynaValidatorForm">
>>   <form-property name="warType" type="java.lang.String"/>
>>
>> Here is my converters (embedded class in my Action)
>>
>>    public class MyConverter1 implements Converter {
>>        @Override
>>        public WarrType convert(Class c, Object s) {
>>            Object result = null;
>>            String ss = (String) s;
>>            if (c.getSimpleName().equals("WarrType")) {
>>                System.out.println(ss);
>>                if (ss.equals("NONE")) result = WarrType.NONE;
>>                if (ss.equals("CALL"))  result = WarrType.CALL;
>>                if (ss.equals("PUT")) result = WarrType.PUT;
>>            }
>>            return (WarrType) result;
>>        }
>>    }
>>
>> and here is the code in my Action:
>>
>>        MyConverter1 mc1 = new MyConverter1();
>>        ConvertUtils.register(mc1, WarrType.class);
>>        BeanUtils.copyProperties(stk, form);
>>
>> I've ensured both Stk and form have the same name "warType". But the
>> copyProperties() takes care of all other properties, except the warType!
>> I
>> have another converter for a date properties coded in similar way and it
>> works. Only this warType doesn't. I have checked the convert() method in
>> MyConverter in debug mode and it can convert correctly. But the
>> stk.warType
>> was not set (although its setWarType() was run with correct parm and
>> output).
>>
>> But if I add this code after the copyProperties() at the above, then it
>> works
>>        BeanUtils.copyProperty(stk, "warType",
>> PropertyUtils.getSimpleProperty(form, "warType"));
>>
>> Any idea why?
>>
>> --
>> View this message in context:
>> http://www.nabble.com/-Struts-1.3--converter-converts-but-not-set-property-tp25531070p25531070.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
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/-Struts-1.3--converter-converts-but-not-set-property-tp25531070p25605191.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] converter converts but not set property

Posted by Arthur Neves <ar...@gmail.com>.
BeansUtils just call your converter, if your form bean property "warType",
will be a 'WarrType' .

On Wed, Sep 23, 2009 at 7:16 AM, senderj <se...@hotmail.com> wrote:

>
> I wrote a converter to convert a enum for BeanUtils.copyProperties().  I
> have
> this in my struts config:
>
> <form-bean name="MyForm"
> type="org.apache.struts.validator.DynaValidatorForm">
>   <form-property name="warType" type="java.lang.String"/>
>
> Here is my converters (embedded class in my Action)
>
>    public class MyConverter1 implements Converter {
>        @Override
>        public WarrType convert(Class c, Object s) {
>            Object result = null;
>            String ss = (String) s;
>            if (c.getSimpleName().equals("WarrType")) {
>                System.out.println(ss);
>                if (ss.equals("NONE")) result = WarrType.NONE;
>                if (ss.equals("CALL"))  result = WarrType.CALL;
>                if (ss.equals("PUT")) result = WarrType.PUT;
>            }
>            return (WarrType) result;
>        }
>    }
>
> and here is the code in my Action:
>
>        MyConverter1 mc1 = new MyConverter1();
>        ConvertUtils.register(mc1, WarrType.class);
>        BeanUtils.copyProperties(stk, form);
>
> I've ensured both Stk and form have the same name "warType". But the
> copyProperties() takes care of all other properties, except the warType! I
> have another converter for a date properties coded in similar way and it
> works. Only this warType doesn't. I have checked the convert() method in
> MyConverter in debug mode and it can convert correctly. But the stk.warType
> was not set (although its setWarType() was run with correct parm and
> output).
>
> But if I add this code after the copyProperties() at the above, then it
> works
>        BeanUtils.copyProperty(stk, "warType",
> PropertyUtils.getSimpleProperty(form, "warType"));
>
> Any idea why?
>
> --
> View this message in context:
> http://www.nabble.com/-Struts-1.3--converter-converts-but-not-set-property-tp25531070p25531070.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
>
>