• Post Reply Bookmark Topic Watch Topic
  • New Topic

Apply immediately a conveter to inputText

 
D. Formenton
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will need to use Javascript for that.
 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
D. Formenton
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!