views:

494

answers:

2

I'm using JSF 1.2 with IceFaces 1.8 in a project here.

I have a page which is basically a big edit grid for a whole bunch of floating-point number fields. This is implemented with inputText fields on the page pointing at a value object with primitive float types

Now, as a new requirement sees some of the fields be nullable, I wanted to change the value object to use Float objects rather than primitive types. I didn't think I'd need to do anything to the page to accomodate this.

However, when I make the change I get the following error:

/pages/page.xhtml @79,14 value="#{row.targetValue}": java.lang.IllegalArgumentException: argument type mismatch

And

/pages/page.xhtml @79,14 value="#{row.targetValue}": java.lang.IllegalArgumentException: java.lang.ClassCastException@1449aa1

The page looks like this:

<ice:inputText value="#{row.targetValue}" size="4">
  <f:convertNumber pattern="###.#" />
</ice:inputText>

I've also tried adding in <f:convert convertId="javax.faces.Float" /> in there as well but that doesn't seem to work either! Neither does changing the value object types to Double.

I'm sure I'm probably missing something really simple but I've been staring at this for a while now and no answers are immediately obvious!

+1  A: 

After some investigation (see e.g. here, here and here) that <f:convertNumber> is the problem. It seems that the number it converts to is dependent on the input you give it - it could be an integer or a floating point number. In other words, it doesn't look at the target type - it just generates an instance of java.lang.Number. Which is hardly ideal, although I can't determine whether this is because somewhere I'm using an old version of JSF or EL or something like that.

There seem to be three solutions:

  1. Use java.lang.Number as your value object type;
  2. Write your own converter;
  3. Don't use <f:convertNumber>.

Unfortunately #1 isn't an option for me for other reasons, and I don't want to write my own converter at the moment. However if I change the code to remove the convertNumber, everything seems to work OK. (I've also updated the value object type to Double which was suggested in one of the links I looked at).

That prevents the exceptions, and it looks like JSF is still doing what I want it to do. Just annoying that it seems you can't specify convertNumber and the convert type in the same instance.

Phill Sacre
the number converter, in myfaces at least uses `DecimalFormat` to parse the value, so that's the ideal way.
Bozho
A: 

JSF Mojarra 1.2 existed for 4 years and many, many bugs have been fixed in years. Are you sure you're using the latest? It's currently 1.2_14 which is available here. Apart from Mojarra 2.0.2 (as per the comment in your question) I just also tried 1.2_12 at Tomcat 6.0.20 and still can't reproduce it.

BalusC
According to the manifest I'm using 1.2_13-b01-FCS. I wonder if it's something to do with my application config somehow if you can't reproduce it. Strange :-/
Phill Sacre
Which server are you using? The root cause of the problem may be in its EL implementation instead. But then I really need to know the stacktrace...
BalusC
It's Tomcat 6.0.14. Unfortunately the stack trace has not been logged anywhere, wonder if IceFaces intercepted it. I will fiddle with log settings, but will have to come back to this next week as I'm away for a few days!
Phill Sacre
The log should by default be in one of the files in `Tomcat/logs`.
BalusC