In PrimeFace’s inputText, I need to call function f1() when any key is pressed.
To implement this, in xhtml file I have:
<p:inputText id="userName" onkeyup="#{myBean.f1()}" >
And in my MyBean.java i have declared this function:
public void f1()
{
// somecode
}
But this code throws an exception:
javax.faces.FacesException: javax.el.ELException: /index.xhtml
@103,191 onkeyup=”#{MyBean.f1()}”: java.lang.NullPointerException
If you want to call a java method you should use
p:ajax eventinstead ofonkeyupattributein other words onkeyup is for calling js functions like
onkeyup="alert('hello')"about the exception you got : its cause you page tried to execute the
f1method on page load and not on keyup event – for example if youf1method would have return a string that string would replace the#{myBean.f1()}and your generated page would look like this: