problem with f:converter

I am using f:converter with an inputText component. I am getting the following error

java.lang.IllegalArgumentException: argument type mismatch

Here is the code for the inputText.

<h:inputText value="#{item.unitPrice}" size="10">

<f:convertNumber maxFractionDigits="2" minFractionDigits="2"/>

</h:inputText>

What is wrong with the code.

[499 byte] By [Jatin_Kulkarnia] at [2007-11-26 18:46:37]
# 1
How is unitPrice defined? If your using myFaces, it should be defined as a Number. Not sure, but I think the Sun RI would allow it to be declared as a Double.
jhaleya at 2007-7-9 6:20:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
I have defined it as Float.
Jatin_Kulkarnia at 2007-7-9 6:20:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
put a breakpoint to see what data type is expected in the setter parm and change accordingly.i think it might have to be big decimal
mel123a at 2007-7-9 6:20:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

I did the same with the myFaces implementation. The type would change depending upon what was typed in. I saw a long with a integer and a Float or Double (can抰 remember) with a non integer. To get around this, I declared it as a Number. A coworker is using the Sun RI and has no problem with a declaring it as a Double.

jhaleya at 2007-7-9 6:20:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

I tried with Double but the problem remains. Here is the code

<h:inputText value="#{item.discount}" size="10">

<f:convertNumber maxFractionDigits="2" minFractionDigits="2"

type="number"/>

</h:inputText>

the bean getter and setter

public Double getDiscount(){

return discount;

}

public void setDiscount(Double discount){

this.discount = discount;

}

Jatin_Kulkarnia at 2007-7-9 6:20:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Have you followed mel123 suggestion? And again, I could not get Double to work either. I had to declare as a 揘umber? the superclass of 揇ouble?. When testing enter integers and non-integers.
jhaleya at 2007-7-9 6:20:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
I tried to put breakpoint on the setter. The error occurs when the form is submitted and before the setter is called. This way I am not able to debug the setter line.
Jatin_Kulkarnia at 2007-7-9 6:20:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
I recommended to use BigDecimal for prices or for decimal values which you want to calculate strictly with. And this converter just works with BigDecimal in here.Didn't you know about wome weird "features" of floating point calculations? Try adding 0.1 everytime in a loop.
BalusCa at 2007-7-9 6:20:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
I used BigDecimal as suggested, but the error still occurs.
Jatin_Kulkarnia at 2007-7-9 6:20:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
Can any one help me with this.
Jatin_Kulkarnia at 2007-7-9 6:20:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

Looking to the variabele name of the valuebinding: "item", I am guessing that this inputText component is been put in an iterated list like a dataTable. If this is right; does it work anyway if you put it in a dummy test component outside the datatable? If it works, then you might review and redesign your data loading logic.

BalusCa at 2007-7-9 6:20:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12
I had the exact same problem and suggested this solution several time above. Have you tried defining discount like this?private Number discount;
jhaleya at 2007-7-9 6:20:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13

This all just works here:

JSF<h:inputText value="#{myBean.bigDecimal}">

<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />

</h:inputText>

<h:inputText value="#{myBean.number}">

<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />

</h:inputText>

<h:inputText value="#{myBean.double1}">

<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />

</h:inputText>

<h:inputText value="#{myBean.double2}">

<f:convertNumber minFractionDigits="2" maxFractionDigits="2" />

</h:inputText>

MyBeanprivate BigDecimal bigDecimal;

private Number number;

private Double double1;

private double double2;

Again: the data loading logic of the values might be wrong. For example, the value may be null while the converter is invoked in the 3rd JSF phase.

BalusCa at 2007-7-9 6:20:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 14
Did you try to submit the form which has the f:convertNumber. In my case I have three pages page1, page2 and page3. Page2 is for user editing and it contains f:convertNumber. When displaying the page2, convertNumber works correctly but when I try to submit the page I get this
Jatin_Kulkarnia at 2007-7-9 6:20:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 15
> Did you try to submit the form which has the> f:convertNumber. Yes.Tested on WSAD 5.1.1 (Eclipse 3.1 based) with JSF 1.1_02 and on Eclipse 3.2 with Glassfish b48 and JSF 1.2_03.
BalusCa at 2007-7-21 17:28:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...