views:

28

answers:

1

I if have a method signature as follows

public void deposit(@RequestParam("accountId") Integer accountId, 
                    @RequestParam("amount") BigDecimal amount) {...}

And because i have a locale specific decimal value which needs to be converted to a BigDecimal, is there some annotation which allows me to set up incoming data such as @Decimal("###.###,##") or something else ???

+1  A: 

Spring 3 has @NumberFormat annotation:

public void deposit(@RequestParam("accountId") Integer accountId,  
    @RequestParam("amount") @NumberFormat(pattern = "###.###,##") BigDecimal amount) 
{...} 

You need <mvc:annotation-driven> to enable it.

See also:

axtavt
@axtavt Nice one (+1) Do you know if i can register **a global converter** to avoid @NumberFormat annotation ???
Arthur Ronald F D Garcia
@Arthur: Perhaps you can install a custom formatter for `BigDecimal` by customizing `FormattingConversionServiceFactoryBean`, see how it's done in `mvc-showcase`.
axtavt