I'm using Primefaces 3.3.1 and have a <p:selectOneMenu> where I'm selecting a new value. When selecting a new value a valueChangeListener-method is being called where the value is being processed. Like this:
<h:form>
<p:selectOneMenu id="signature-menu" value="#{objectBuffertBean.loggedInSignature}" effect="fold" style="width: 125px;">
<p:ajax event="change" update="signature-menu"
listener="#{loginBean.changeSignature()}" />
<f:selectItems value="#{signaturesBean.signatures}" />
</p:selectOneMenu>
</h:form>
LoginBean.java:
public void changeSignature(ValueChangeEvent e) {
if (e.getNewValue() != null) {
try {
WebDB db = new WebDB();
SessionHandler.getInstance().
getCurrentObjectBuffert().setSignature(
db.getSignatureBySignatureFromWebDb(
(String) e.getNewValue()
));
} catch (DatabaseException e1) {
e1.printStackTrace();
}
}
}
But, the strange thing is that when I'm selecting a new value I get this exception:
javax.el.MethodNotFoundException: Method changeSignature not found
And it works! the method is being called somehow and the new value is being processed!! Is there anyone who have had the same strange complication?
You're confusing
valueChangeListenerattribute ofUIInputwithlistenerattribute of<p:ajax>/<f:ajax>. TheValueChangeEventargument is only supported on the method behindvalueChangeListenerattribute. The method behind thelistenerattribute of<p:ajax>/<f:ajax>must takeAjaxBehaviorEventargument (or just nothing).So
or
Note that the submitted value is already set on the property behind the
UIInputcomponent'svalueattribute, so there's no need to get it by the event somehow. This is because this runs during invoke action phase instead of the validations phase like thevalueChangeListener. Also, thevalueChangeListenershould technically only be used when you intend to have both the old and the new value in the method.Unrelated to the concrete problem, the
event="change"attribute of<p:ajax>is already the default. You can just omit it. Also those method parentheses from thelistenerattribute should preferably be omitted as it adds no value. Just uselistener="#{loginBean.changeSignature}".