struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gundersen, Richard" <Richard.Gunder...@london-scottish.com>
Subject RE: Re: DynaValidatorForm and BigDecimal problem
Date Fri, 02 Mar 2007 10:42:20 GMT
Hi

Yep, I realised that was a limitation as I was putting it in. But for
me, this is still quite a nice solution because the values need to be
very precise so using BigDecimal all the way through gives me a (perhaps
false) sense of security. Also, it's a big system and I have to change a
lot of fields, and I think this is slightly less work than converting
all fields to Strings. 

Both solutions are very good though so I'm really grateful for the help
I've been given.

Richard Gundersen
Java Developer
 
Email: richard.gundersen@london-scottish.com
Phone: 01618302398
Fax: 01618342536
London Scottish Bank plc
24 Mount Street
Manchester
M2 3LS

-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Laurie Harper
Sent: Thursday, March 01, 2007 8:40 PM
To: user@struts.apache.org
Subject: Re: DynaValidatorForm and BigDecimal problem

Bear in mind that this way, if the user types in 'abc' for one of your 
money fields, you wont be able to re-display their incorrect input. 
That's the other major reason for making your form fields String-typed.

L.

Gundersen, Richard wrote:
> Actually, I tried out your first solution, and it actually works very
> nicely too, so I'm going to go with that one for now!
> 
> Richard Gundersen
> Java Developer
>  
> Email: richard.gundersen@london-scottish.com
> Phone: 01618302398
> Fax: 01618342536
> London Scottish Bank plc
> 24 Mount Street
> Manchester
> M2 3LS
> 
> -----Original Message-----
> From: Ed Griebel [mailto:edgriebel@gmail.com] 
> Sent: Thursday, March 01, 2007 4:13 PM
> To: Struts Users Mailing List
> Subject: Re: DynaValidatorForm and BigDecimal problem
> 
> It has nothing to do with Struts, the error message is saying that
> commons BeanUtils cannot convert the string from the form submit into
> a BigDecimal. Turns out that your issue is BigDecimal is not as
> permissive as Double when it converts a non-numeric string to a
> BigDecimal. If a string is not a number, Double converts it to 0.0,
> but BigDecimal will throw an exception, even for an empty string.
> 
> Struts copies screen fields to formbean fields in
> RequestUtils.populate() before it does anything else including
> validation. So, even though there's not a value in the field (actually
> *because* there's no numeric value!) populate() re-throws the
> exception that you are seeing.
> 
> To get it to work you could create and register a custom converter
> that will do some checking on the string before it passes it to the
> BigDecimal(String) constructor.  You will need a class that extends
> org.apache.commons.beanutils.converters.BigDecimalConverter, and
> register your custom converter by calling ConvertUtils.register(new
> <your class>(), BigDecimlal.class);
> 
> Or, you could instead use an alternate approach that many (me
> included) recommend, of having all formbean fields be Strings. You
> would have a String display field and a second field that is a
> non-string, and have this populated by your action after validation
> succeeds.
> 
> -ed
> 
> On 3/1/07, Gundersen, Richard <Richard.Gundersen@london-scottish.com>
> wrote:
>> Hi
>>
>> Has anyone had problems with BigDecimal and DynaValidatorForms?
>>
>> I've got a form with two fields (advisorFee and grossIncome) defined
> as
>> java.lang.Double. I want to change them to java.math.BigDecimal
> because
>> they are money fields.
>>
>> If I change advisorFee to BigDecimal, the validation fails when I
> enter
>> a value into grossIncome, even though this is still a Double.
>>
>> This is the error I get:
>>
>> javax.servlet.ServletException: BeanUtils.populate
>>
>> org.apache.struts.util.RequestUtils.populate(RequestUtils.java:453)
>>
>> [Caused by]...
>>
>> org.apache.commons.beanutils.ConversionException
>>
>>
>
org.apache.commons.beanutils.converters.BigDecimalConverter.convert(BigD
>> ecimalConverter.java:117)
>>
>> This doesn't make any sense to me. Is it possible that it's a bug in
>> 1.3.5? Why should changing the definition of one field change the
>> behaviour of another (they are not linked in any way e.g. in the
>> validation rules)
>>
>>
>> Regards
>>
>> Richard Gundersen
>> Java Developer
>>
>> Email: richard.gundersen@london-scottish.com
>> Phone: 01618302398
>> Fax: 01618342536
>> London Scottish Bank plc
>> 24 Mount Street
>> Manchester
>> M2 3LS
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email 
> ______________________________________________________________________
> 
> *** Disclaimer *** 
> 
> This electronic communication is confidential and for the exclusive
use of the addressee. It may contain private and confidential
information. The information, attachments and opinions contained in this
E-mail are those of its author only and do not necessarily represent
those of London Scottish Bank PLC or any other members of the London
Scottish Group. 
> 
> If you are not the intended addressee, you are prohibited from any
disclosure, distribution or further copying or use of this communication
or the information in it or taking any action in reliance on it. If you
have received this communication in error please notify the Information
Security Manager at ISM@London-Scottish.com as soon as possible and
delete the message from all places in your computer where it is stored. 
> 
> We utilise virus scanning software but we cannot guarantee the
security of electronic communications and you are advised to check any
attachments for viruses. We do not accept liability for any loss
resulting from any corruption or alteration of data or importation of
any virus as a result of receiving this electronic communication. 
> 
> Replies to this E-mail may be monitored for operational or business
reasons. London Scottish Bank PLC is regulated by the Financial Services
Authority.
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.


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


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

*** Disclaimer *** 

This electronic communication is confidential and for the exclusive use of the addressee.
It may contain private and confidential information. The information, attachments and opinions
contained in this E-mail are those of its author only and do not necessarily represent those
of London Scottish Bank PLC or any other members of the London Scottish Group. 

If you are not the intended addressee, you are prohibited from any disclosure, distribution
or further copying or use of this communication or the information in it or taking any action
in reliance on it. If you have received this communication in error please notify the Information
Security Manager at ISM@London-Scottish.com as soon as possible and delete the message from
all places in your computer where it is stored. 

We utilise virus scanning software but we cannot guarantee the security of electronic communications
and you are advised to check any attachments for viruses. We do not accept liability for any
loss resulting from any corruption or alteration of data or importation of any virus as a
result of receiving this electronic communication. 

Replies to this E-mail may be monitored for operational or business reasons. London Scottish
Bank PLC is regulated by the Financial Services Authority.
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.

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


Mime
View raw message