This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JSF and the fly likes f:convertNumber not working in dataTable context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "f:convertNumber not working in dataTable context" Watch "f:convertNumber not working in dataTable context" New topic
Author

f:convertNumber not working in dataTable context

Will Wijgergangs
Greenhorn

Joined: Jan 11, 2010
Posts: 4
I'm trying to use a f:convertnumber in a datatable, for some kind of reason it never seems do anything with the convertNumber in the datatable.
Below a piece of the datatable and the associated java program.
The preceding outputtext (employee.number) works fine, but the inputtext in the dataTable isn't working.
Has anybody an idea what the reason is ??
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16160
    
  21

Welcome to the JavaRanch, Will!

We have a "Code" tag that can be used to preserve the formatting of your code when you post it. You can insert it by clicking the "Code" button that's in the row of buttons above the message editing area.

convertNumber does work on both input and output in datatables. Could you tell us what you mean when you say it "doesn't work"?


Customer surveys are for companies who didn't pay proper attention to begin with.
Will Wijgergangs
Greenhorn

Joined: Jan 11, 2010
Posts: 4
Thanks Tim for your tip of the code tag, I changed my post immediately.

The problem is when I uses a convertNumber not in a datatable it works fine.

In the mentioned example the number is formatted as 123.456 based on the pattern '###.###'.

But when I try to use it in a datatable it simply seems to ignore the convertNumber.
The monthSalaries are presented in the way they are returned from the program (500050, 200000 and 150000) and not as 5000.50 2000.00 and 1500.00 which I expected from the pattern.
The pattern is not the problem (I uses the most crazy patterns) but it looks like the convertNumber isn't recognized, I uses inputText and ouputText tags both the same problem.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16160
    
  21

That's not a formatting issue, the decimals are in the wrong place!

Is the property being referenced a number, or is it a String? The get-method should be returning a float or double.
Will Wijgergangs
Greenhorn

Joined: Jan 11, 2010
Posts: 4
I've tried it with returning a float and a double but I don't think this is the problem.
In my understanding the purpose of a pattern is to make up a String with a kind of format.

And it is working on the employee.number !!!
I can make up this String with any pattern I like.

Today I will try to do some extra testing and will try it once again with returning a float or double.
Tim again thanks for your help
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16160
    
  21

Will Wijgergangs wrote:I've tried it with returning a float and a double but I don't think this is the problem.
In my understanding the purpose of a pattern is to make up a String with a kind of format.


Not in this case. That's why it's called convertNumber. This particular converter isn't a generic String reformatter.
Will Wijgergangs
Greenhorn

Joined: Jan 11, 2010
Posts: 4
It works great thanks Tim !!

The bold word Number in your last post triggered me.
I did test with a float or double however I used the primitives which of course won't work.
So implementing a Float as returning type gives the desired result.

Once again thanks for your help !!

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: f:convertNumber not working in dataTable context