2 Replies Latest reply on Oct 20, 2009 5:01 PM by kidala

    convertnumber  argument type mismatch

    ajanz
      i got a simple page with an inputtext and a convertnumber. but i only could bind it to a property of primitve type double, if i use Double i got  "argument type mismatch"

      i use Sun's JSF 1.2_12  and Seam 2.0.2 SP1

      my page is

      <?xml version="1.0" encoding="ISO-8859-1"?>
      <ui:composition  xmlns="http://www.w3.org/1999/xhtml"
                       xmlns:ui="http://java.sun.com/jsf/facelets"
                       xmlns:h="http://java.sun.com/jsf/html"
                       xmlns:f="http://java.sun.com/jsf/core"
                       xmlns:rich="http://richfaces.org/rich"
                       xmlns:a4j="http://richfaces.org/a4j"
                       xmlns:s="http://jboss.com/products/seam/taglib">



      <a4j:form>


      <rich:panel>
      <rich:messages id="messages"  />
      <br/>
      <h:inputText value="#{TestBean.d1}"  >
         <f:convertNumber maxFractionDigits="3" minFractionDigits="2" minIntegerDigits="1" maxIntegerDigits="15"
                             groupingUsed="true"                 
                             />
                             </h:inputText>
      <h:commandButton value="Submit" ></h:commandButton>
      </rich:panel>
      </a4j:form> 
      </ui:composition>

      bean code is


      @Name("TestBean")
      @Scope(ScopeType.PAGE)
      public class TestBean {
           
           boolean disabled= false;
           
           public boolean isDisabled() {
                System.out.println("isdisabled=" + disabled);
                return disabled;
           }

           public void setDisabled(boolean disabled) {
                this.disabled = disabled;
           }

           public void switchdis(){
                System.out.println("switchdis!!!!");
                disabled =!disabled;
           }
           
           Double d1;
           public Double getD1() {
                return d1;
           }

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

           double d2;
           public double getD2() {
                return d2;
           }

           public void setD2(double d2) {
                this.d2 = d2;
           }

           
           

      }


      i must use Double because i must allow using null values
        • 1. Re: convertnumber  argument type mismatch
          ajanz
          finally...after struggling for days i got the answer...

          it's nothing about seam

          it's only jsf

          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.

          so usinger Number solved my problem
          • 2. Re: convertnumber  argument type mismatch
            kidala

            Thank you Sasha for your investigation!!


            I had the same problem and your post helped me!!


            Thanks a lot!!