2 Replies Latest reply on Mar 26, 2009 7:03 AM by Sascha Janz

    trouble using convertnumber

    Sascha Janz Master

      i use richfaces 3.3.0 GA , Jboss 4.2.2 GA and SEAM 2.0.2

      i bound an inputtext on a Double in my bean

      simple code is

      Double d1;
       public Double getD1() {
       return d1;
       }
      
       public void setD1(Double d1) {
       this.d1 = d1;
       }


      <h:inputText value="#{TestBean.d1}" >
      


      but if i add a convertnumber like


      <h:inputText value="#{TestBean.d1}" >
      <f:convertNumber type="number" maxFractionDigits="2" minFractionDigits="2" groupingUsed="true" />
       </h:inputText>
      


      i got following error . any ideas to solve that?

      SCHWERWIEGEND: /test/test1.xhtml @21,39 value="#{TestBean.d1}": java.lang.Illega
      lArgumentException: argument type mismatch
      java.lang.IllegalArgumentException: argument type mismatch
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at javax.el.BeanELResolver.setValue(BeanELResolver.java:108)
       at javax.el.CompositeELResolver.setValue(CompositeELResolver.java:68)
       at com.sun.faces.el.FacesCompositeELResolver.setValue(FacesCompositeELRe
      solver.java:100)
       at org.jboss.el.parser.AstPropertySuffix.setValue(AstPropertySuffix.java
      :73)
       at org.jboss.el.parser.AstValue.setValue(AstValue.java:84)
       at org.jboss.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:24
      9)
       at com.sun.facelets.el.TagValueExpression.setValue(TagValueExpression.ja
      va:93)
       at javax.faces.component.UIInput.updateModel(UIInput.java:771)
       at javax.faces.component.UIInput.processUpdates(UIInput.java:703)
       at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.
      java:1081)
       at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.
      java:1081)
       at org.ajax4jsf.component.UIAjaxForm.processUpdates(UIAjaxForm.java:98)
       at org.ajax4jsf.component.AjaxViewRoot$2.invokeContextCallback(AjaxViewR
      oot.java:416)
       at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:23
      8)
       at org.ajax4jsf.component.AjaxViewRoot.processUpdates(AjaxViewRoot.java:
      432)
       at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelVal
      uesPhase.java:78)
       at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
       at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
      
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
      icationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
      ilterChain.java:206)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
      .java:83)
       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
      .java:69)
       at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
      .java:69)
       at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
      .java:69)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
      
       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFil
      ter.java:390)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
       at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
      .java:69)
       at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter
      .java:69)
       at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
      icationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
      ilterChain.java:206)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
      lter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
      icationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
      ilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
      alve.java:230)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
      alve.java:175)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
      yAssociationValve.java:179)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
      torBase.java:432)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
      e.java:84)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
      ava:127)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
      ava:102)
       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedC
      onnectionValve.java:157)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
      ve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
      a:262)
       at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcesso
      r.java:856)
       at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.pr
      ocess(Http11AprProtocol.java:566)
       at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:15
      08)
       at java.lang.Thread.run(Thread.java:595)
      


        • 1. Re: trouble using convertnumber
          Ilya Shaikovsky Master

          not related to RF.. but anyway.. you defined minFractionDigits = 2. So while you will enter for example "312" - there will be exception and validation error. But after you enter "321.00" all will works fine.

          I've removed this attribute and any numbers started to be updated correctly. For more information visit JSF resources.

          • 2. Re: trouble using convertnumber
            Sascha Janz Master

            sorry for that. but i already asked in sun's jsf forum. the answer there was that my code is right and it might be some trouble with jboss el....

            after struggling with that problem for days i now got finally my answer....

            1. According to JSF specification, if you use f:convertNumber, the type of the result depends on the input: if the user enters 0 you will get a Long, if he enters 0.1 you'll get a Double, no matter what you have on your bean. So the correct way to work with f:convertNumber (no matter what other attributes you use, like pattern, or so) is to use a Number on the backing bean, not Integer, or int, or float, or Float, or Double or anything like that.
            2. If you use f:convert id="javax.faces.Double" or the converter attribute in the input controls you will always get a Double, but then you cannot specify any formatting.