Hi guys,

Borislav - thank you for the time you spent debugging this issue :-)

So now I wonder - is it o.k. to use typed properties in my Action Forms?
Or is there an important reason why I should Strings only?

I don't add my Action Form properties to the Struts config file. Is it
o.k. - or am I missing something here?

Thanks
Rivka
 
-----Original Message-----
From: Borislav Sabev [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 11, 2005 7:38 PM
To: Struts Users Mailing List
Subject: Re: Using struts forms as Value Objects: your opinion?

Nitish Kumar wrote:

>I think raghavendra is right.
>Rivka, your code is working because you are using primitive type int
and not
>the wrapper type Integer.
>In case of primitive type in case of any exception, it gives you a
default
>value.
>
>
>Thanks and Regards, 
>Nitish Kumar 
>
>
>  
>
So after small debugging session I found why it works for Integers and 
not for dates (at least in my case)
all classes  that implment Convertors interface in BeanUtils, have 
something like this as implementation of convert() method:
    public Object convert(Class type, Object value) {
        if (value == null) {
            if (useDefault) {
                return (defaultValue);
            } else {
                throw new ConversionException("No value specified");
            }
        }

        if (value instanceof Date) {
            return (value);
        }

        try {
            return (Date.valueOf(value.toString()));
        } catch (Exception e) {
            if (useDefault) {
                return (defaultValue);
            } else {
                throw new ConversionException(e);
            }
        }

    }

In case of the Integer there is pre-load default value and EVEN if 
conversion fails during the population phase, it just use is the dafault

value (and you think it's parsed correctly). In the previous example its

a coincidence that Rivka have 0 as default value (it's just the same 
value as init value of IntegerConverter).
The strange point is that I didn't find how can I set a default date 
value ... if someone knows it, please share this knowledge here.

For sure this is not a big discovery, but I spent a lot of hours to 
udnerstand it and I though that this should be described somewhere at 
some public place ... that's why I was a bit bitter in my previuos posts

Regards
Borislav
**************************************************************************************************
The contents of this email and any attachments are confidential.
They are intended for the named recipient(s) only.
If you have received this email in error please notify the system manager or  
the 
sender immediately and do not disclose the contents to anyone or make copies.

** eSafe scanned this email for viruses, vandals and malicious content. **
**************************************************************************************************

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to