| Author |
Apply immediately a conveter to inputText
|
D. Formenton
Ranch Hand
Joined: Mar 20, 2008
Posts: 46
|
|
Hi!
I have:
<h:inputText id="price" value="#{articoliController.selected.price}" immediate="true">
<f:convertNumber pattern="#,##0.00" />
</h:inputText>
and I wold like that when a user edit the field and then LOST THE FOCUS (going to the next field)
the converter format immediately the inputText "price".
Is it possible?
Thank you
Domenico
|
 |
Hebert Coelho
Ranch Hand
Joined: Jul 14, 2010
Posts: 754
|
|
|
You will need to use Javascript for that.
|
[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14572
|
|
You need AJAX. And I don't think "immediate" is valid for the inputText tag. For one thing, "immediate" means "don't send down values", so that kind of defeats the purpose.
What you're really hoping for isn't so much to apply the converter as it is to send down the value (which passes it through the input side of the converter), update the backing bean, then reRender the result back to the displayed View (passing the value through the output side of the converter). That's what would happen on a normal form submit, but you don't want to wait that long - you want it on the "onblur" Javascript event. For that, like I said, you need AJAX.
Also, the backing bean updating isn't optional. Converters are only used when sending to/receiving from a backing bean. Usually, you won't care, since the data is also validated, but it is something to keep in mind, that the bean's property will be updated onblur instead of waiting for a normal submit.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
D. Formenton
Ranch Hand
Joined: Mar 20, 2008
Posts: 46
|
|
Thank you Tim, for your exaustive answer!
I added:
<p:ajax event="blur" update="price"/> (p: from primefaces)
ad it works!
Thank you again
Domenico
|
 |
 |
|
|
subject: Apply immediately a conveter to inputText
|
|
|