简体   繁体   English

a4j:ajax侦听器异常MethodNotFoundException

[英]a4j:ajax listener exception MethodNotFoundException

I started study RichFaces 4.2.2 and have a problem in simple example, I have an xml: 我开始研究RichFaces 4.2.2,并在一个简单示例中遇到了问题,我有一个xml:

<ui:define name="content">       
        <h:form>
            <rich:panel style="width: 50%">
                <h:panelGrid columns="2">
                    <h:outputText value="Name:"/>
                    <h:inputText id="inp" value="#{echoBean.name}">
                        <a4j:ajax event="keyup" render="echo count"  listener="#{echoBean.countListener}"/>
                    </h:inputText>

                    <h:outputText value="Echo:"/>
                    <h:outputText id="echo" value="#{echoBean.name}"/>

                    <h:outputText value="Count:"/>
                    <h:outputText id="count" value="#{echoBean.count}"/>
                </h:panelGrid>
                <a4j:commandButton value="Submit" actionListener="#{echoBean.countListener}" render="echo, count"/>
            </rich:panel>
        </h:form>

</ui:define>

and a simple bean: 和一个简单的bean:

@Component("echoBean")
@Scope(value = "session")
public class EchoBean {
private String name;
private Integer count = 0;

//getter setter methods here

public void countListener(ActionEvent event) {
    count++;
    }
}

And when i try to print in inputText i have exception: 当我尝试在inputText中打印时,出现异常:

Caused by: javax.el.MethodNotFoundException: /home.xhtml @35,112 listener="#{echoBean.countListener}": Method not found: com.example.training.bean.EchoBean@d523fa.countListener()
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:102)
at org.ajax4jsf.component.behavior.MethodExpressionAjaxBehaviorListener.processAjaxBehavior(MethodExpressionAjaxBehaviorListener.java:71)
at javax.faces.event.AjaxBehaviorEvent.processListener(AjaxBehaviorEvent.java:113)
at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:98)
at org.ajax4jsf.component.behavior.AjaxBehavior.broadcast(AjaxBehavior.java:348)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:763)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:775)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1267)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
... 19 more

But why? 但为什么? With button this same listener works just fine and in docs for "listener" parameter in a4j:ajax it says that: 使用按钮,这个相同的侦听器可以正常工作,并且在a4j:ajax中的“ listener”参数的文档中说:

The expression must evaluate to a public method that takes an ActionEvent parameter, with a return type of void, or to a public method that takes no arguments with a return type of void 该表达式必须计算为带ActionEvent参数且返回类型为void的公共方法,或者为不带参数返回值类型为void的公共方法。

Why it uses countListener() without ActionEvent parameter? 为什么使用不带ActionEvent参数的countListener() I don't get it. 我不明白

For you to be able to use the listener attribute with RF4, your listener method should take an argument of the AjaxBehaviorEvent type, not an ActionEvent type. 为了使RF4可以使用listener属性,您的listener方法应采用AjaxBehaviorEvent类型的参数,而不是ActionEvent类型的参数。 The other alternative approach as you can see from the error message is to define a standard java method that doesn't take arguments and has a void return type as in 从错误消息中可以看到的另一种替代方法是定义一个标准的Java方法,该方法不带参数,并且返回类型为void

   public void countListener();

Why it uses countListener() without ActionEvent parameter? 为什么使用不带ActionEvent参数的countListener()? I don't get it. 我不明白

That's the contract for the API, you're required to conform to be able to use it. 那是API的合同,您必须遵守才能使用它。

使用以下签名无效的bean函数作为返回类型ActionEvent对象作为参数bean函数的示例如下

public void countListener(ActionEvent event) {}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM