views:

574

answers:

0

Hi. I'm having some problems trying to convert/validate a java.math.BigDecimal[][] in a Struts 2 action class. I need to display the values localized (pt_BR) so I wrote a BigDecimal converter. Then I wrote a simples MyAction-convertion.properties file:

quadroInvestimentos=my.package.converter.BigDecimalConverter

My action class has a property that match the name listed in the convertion file: private BigDecimal[][] quadroInvestimentos and the necessary get/set methods. The get method is slightly different that what you expect:

public BigDecimal[][] getQuadroInvestimentos() {
    if (this.quadroInvestimentos == null) {
        this.quadroInvestimentos = new BigDecimal[size][anotersize];
    }
    return this.quadroInvestimentos;
}

I coded the method this to avoid null pointer exceptions when JSP is submited (Struts don't know how to create the matrix, its dimensions, for example).

When my page is to be displayed the BigDecimalConverter.convertToString() method is executed for each value in the matrix. When my page is submited the BigDecimalConverter.convertFromString() does not execute to convert the Strings back to BigDecimal and the message Invalid field value for field xyz is displayed. I thought that registering a custom converter was the only necessary step to guarantee proper convertion to and from String, but Struts 2 is not that simple...

Do you know how to handle BigDecimal[][] convertion in Struts 2?