2012-10-12 41 views
2

我开始研究RichFaces的4.2.2并有简单的例子,一个问题,我有一个xml:A4J:AJAX监听例外MethodNotFoundException

<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> 

和一个简单的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++; 
    } 
} 

而当我尝试在inputText中打印时,我有例外:

Caused by: javax.el.MethodNotFoundException: /home.xhtml @35,112 listener="#{echoBean.countListener}": Method not found: [email protected]() 
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 

但是为什么?使用按钮这个相同的侦听器工作得很好,并在文档中的“听众”参数在a4j:ajax它说:

该表达式必须评估为一个公共方法,需要一个ActionEvent参数,返回类型为void,或者公共方法不带参数,返回类型为void

为什么它使用countListener()而没有ActionEvent参数?我不明白。

回答

3

为了能够在RF4中使用listener属性,您的侦听器方法应采用AjaxBehaviorEvent类型的参数,而不是ActionEvent类型。你可以从错误消息中看到的其他替代方法是定义不带参数标准的Java方法,具有void返回类型为

public void countListener(); 

为什么它使用countListener()没有动作事件参数?我不明白。

这是API的合同,您需要遵守才能使用它。

+0

THX我看了一下面孔动作事件,并没有找到有关AjaxBehaviourEvent什么 – Wizzard

+0

AjaxBehaviorEvent – user738048

1

的返回类型具有以下签名 无效使用bean功能 ActionEvent对象作为参数 例为bean功能如下

public void countListener(ActionEvent event) {}