vendredi 17 juillet 2015

ognl.noconversionpossible when using TreeMap and BigDecimal (Struts2)

I am developping a Struts2 application.

I get stucked on this error when posting a form : HTTP 400 State - The request contains invalid parameters (translated from french).

The form I am using is created from a TreeMap, with BigDecimals for values :

private TreeMap<Integer, BigDecimal> myTreeMap;

In ftl :

<#list model.myTreeMap?keys as key> 
     <tr>
          <td> ${key} </td>  
          <td> <@s.textfield name="model.myTreeMap[${key}]" value="${model.myTreeMap.get(key)}" maxlength=3 /> </td> 
     </tr>
</#list>  

The problem is, it feels like OGNL is treating the values as Integer, not BigDecimal. Indeed, when going into debug inside the TreeMap setter, I get this error :

ognl.noconversionpossible

I have seen this error before concerning dates, and what I did was creating a custom convertor. But this time the problem seems a bit different. Indeed, if I do not use a TreeMap, but just a single BigDecimal in the form, then struts manages to populate correctly my Java Object.

So my questions are :

  1. Do TreeMaps need special behaviour with Struts2/OGNL?
  2. Do I need to create a custom convertor for BigDecimal or TreeMaps, or something else?

Aucun commentaire:

Enregistrer un commentaire