title: Cannot store a number with f:convertNumber into a Map
body: <p>I have a strange situation where i the f:convertNumber doesnt work when trying to store it to a untyped Map.</p>
  
  <p>I expect the number to be stored as a java.lang.Double object in the Map.</p>
  
  <hr>
  
  <p>Here's the xhtml excerpt :</p>
  
  <pre><code>&lt;h:inputText value="#{tInputBean.generalMap['myNumber']}" id="testNumber"&gt;
      &lt;f:convertNumber /&gt;
  &lt;/h:inputText&gt;
  &lt;p:message for="testNumber" /&gt;
  </code></pre>
  
  <hr>
  
  <p>And here's the bean :</p>
  
  <pre><code>@Named("tInputBean")
  @Scope("view")
  public class TInputBean {
      private Log log = LogFactory.getLog(TInputBean.class);
      private Map generalMap = new HashMap();
  
      // .. and the setter getter
      ....
  }
  </code></pre>
  
  <hr>
  
  <p>And here's my log :</p>
  
  <pre><code>DEBUG PhaseTracker - BEFORE PHASE RESTORE_VIEW 1
  DEBUG PhaseTracker - AFTER PHASE RESTORE_VIEW 1
  DEBUG PhaseTracker - BEFORE PHASE APPLY_REQUEST_VALUES 2
  DEBUG DebugUtil - ============== start debugMap parameter map : ==============
  DEBUG DebugUtil - testNumber='123123123'
  DEBUG DebugUtil - javax.faces.partial.execute='SaveHeader testNumberPanel RPBPanel'
  DEBUG DebugUtil - SaveHeader='SaveHeader'
  DEBUG DebugUtil - javax.faces.partial.render='messages RPBPanel DebugVersionHeader testNumberPanel'
  DEBUG DebugUtil - javax.faces.source='SaveHeader'
  DEBUG DebugUtil - j_idt42='j_idt42'
  DEBUG DebugUtil - javax.faces.ViewState='7088371747667351331:-3641627426454744246'
  DEBUG DebugUtil - transNum='TRX003'
  DEBUG DebugUtil - javax.faces.partial.ajax='true'
  DEBUG DebugUtil - ============== end debugMap parameter map : ==============
  DEBUG PhaseTracker - AFTER PHASE APPLY_REQUEST_VALUES 2
  DEBUG PhaseTracker - BEFORE PHASE PROCESS_VALIDATIONS 3
  DEBUG PhaseTracker - AFTER PHASE PROCESS_VALIDATIONS 3
  DEBUG PhaseTracker - BEFORE PHASE RENDER_RESPONSE 6
  DEBUG PhaseTracker - AFTER PHASE RENDER_RESPONSE 6
  </code></pre>
  
  <hr>
  
  <p>And after the render, <code>&lt;p:message for="testNumber" /&gt;</code> is replaced with : <code>{0}: Conversion error occurred.</code></p>
  
  <hr>
  
  <p>The things i notice is :</p>
  
  <ol>
  <li>There's no exception happening while the conversion error occurs. Nothing is handled by my exceptionhandler which captures and log all exceptions. No exception trace.</li>
  <li>I cannot specify a type like java.lang.Double in the <code>&lt;f:convertNumber&gt;</code> tag.</li>
  </ol>
  
  <hr>
  
  <p>Should i make my own converter for this to work ? Im already imagining things like :</p>
  
  <pre><code>&lt;h:inputText value="#{tInputBean.generalMap['myNumber']}" id="testNumber"&gt;
      &lt;f:converter type="MyDoubleConverter" /&gt;
  &lt;/h:inputText&gt;
  &lt;p:message for="testNumber" /&gt;
  </code></pre>
  
  <p>Please share your opinion on this matter.
  Thank you !</p>
  
  <hr>
  
  <p>UPDATE</p>
  
  <hr>
  
  <p>I've built a simple converter that suits my need, and so far it's been working ok. Here's the code, please share your opinion on this :</p>
  
  <pre><code>@FacesConverter(value="Double")
  public class DoubleConverter implements Converter {
      private Log log = LogFactory.getLog(DoubleConverter.class);
  
      @Override
      public String getAsString(FacesContext context, UIComponent component, Object value) {
          //log.debug("locale : " + context.getViewRoot().getLocale());
          DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(context.getViewRoot().getLocale());
          //log.debug("VALUE == " + value);
          String result = value == null || value.toString().trim().length() == 0 ? null : format.format(value);
          //log.debug("RESULT == " + value);
          return result;
      }
  
      @Override
      public Object getAsObject(FacesContext context, UIComponent component, String value) {
          //log.debug("locale : " + context.getViewRoot().getLocale());
          //log.debug("STRING VALUE == " + value);
          DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(context.getViewRoot().getLocale());
          try {
              Object result = ((value == null) || (value.trim().length() == 0)) ? null : format.parse(value).doubleValue();
              //log.debug("RESULT == " + result);
              return result;
          } catch (Exception e) {
              log.error(e,e);
              throw new ConverterException(e);
          }
      }
  }
  </code></pre>
  
  <p>And here's how my jsf make use of it :</p>
  
  <pre><code>&lt;h:inputText value="#{tInputBean.generalMap['myNumber']}" 
     id="testNumber" converter="Double"/&gt;
  &lt;p:message for="testNumber" /&gt;
  </code></pre>