Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to execute `valueChangeListener` for `p:inputText` without hitting `enter` key?

I'd like to execute valueChangeListener for p:inputText when user changes text and inputText looses focus (onchange). Is this possible? For now it only executed after I press return.

like image 615
Danijel Avatar asked Dec 20 '12 15:12

Danijel


1 Answers

The valueChangeListener method requires a form submit to be invoked. This is a server side event, not a client side event or so. Just changing and blurring the input does by default not submit the form at all. Bring in a <p:ajax> to do the magic.

<p:inputText value="#{bean.inputValue}" valueChangeListener="#{bean.inputChanged}">
    <p:ajax />
</p:inputText>

However, although you didn't tell anything about the concrete functional requirement for which you thought that this is the right solution, I just wanted to mention that the valueChangeListener is more than often the wrong tool for the job you had in mind. Use <p:ajax listener> instead.

<p:inputText value="#{bean.inputValue}">
    <p:ajax listener="#{bean.inputChanged}" />
</p:inputText>

Note that this would then make it possible to pass method arguments by EL 2.2, which would immediately then answer the possible underlying functional requirement of your other — actually pretty poor — question.

<p:inputText value="#{bean.inputValue}">
    <p:ajax listener="#{bean.inputChanged('arg1', 'arg2')}" />
</p:inputText>

Also note that this might not be the solution at all if you're actually interested on the entered value; you could just access the inputValue property directly.

See also:

  • When to use valueChangeListener or f:ajax listener?
like image 188
BalusC Avatar answered Sep 25 '22 17:09

BalusC