Reputation: 131
How do I call a bean method on focus lost?
I tried this,
<h:inputText id="receipeCode" value="#{receipeBean.receipeCode}"
onfocuslost="#{receipeBean.view}" />
However, the method is not called when the cursor is moved to the next input field.
Upvotes: 2
Views: 4864
Reputation: 1109272
The "focus lost" event is called "blur" event. So, you basically need onblur
:
<h:inputText ... onblur="#{receipeBean.view}">
However, this doesn't call the specified method on blur. This merely prints the view
property as a String
representing some JavaScript code during generating the HTML output. It's expecting a getter method something like this:
public String getView() {
return "alert('peek-a-boo')";
}
If you have actually a view()
method, you'll face a PropertyNotFoundException
on this one. Also, this isn't exactly "calling a bean method on blur". This is more "generating JavaScript code which should run on blur".
In order to actually invoke a JSF backing bean method on blur, you need a <f:ajax>
.
<h:inputText ...>
<f:ajax event="blur" listener="#{receipeBean.view}" />
</h:inputText>
Upvotes: 4