提问人:Wizzard 提问时间:10/12/2012 最后编辑:Wizzard 更新时间:4/27/2016 访问量:5093
a4j:ajax 侦听器异常 MethodNotFoundException
a4j:ajax listener exception MethodNotFoundException
问:
我开始学习 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>
和一个简单的 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 中的“listener”参数的文档中,它说:
表达式的计算结果必须为采用 ActionEvent 参数且返回类型为 void 的公共方法,或计算结果为不采用任何参数且返回类型为 void 的公共方法
为什么它不带参数使用?我不明白。countListener()
ActionEvent
答:
3赞
kolossus
10/23/2012
#1
为了能够将该属性与 RF4 一起使用,侦听器方法应采用类型的参数,而不是类型。从错误消息中可以看出,另一种替代方法是定义一个不带参数且具有 void 返回类型的标准 java 方法,如listener
AjaxBehaviorEvent
ActionEvent
public void countListener();
为什么它使用不带 ActionEvent 参数的 countListener()?我不明白。
这是 API 的合约,您需要遵守才能使用它。
评论
0赞
Wizzard
10/25/2012
谢谢,我已经阅读了有关Faces ActionEvent的信息,但没有找到有关AjaxBehaviourEvent的任何信息
1赞
Sankar R.K
#2
使用具有以下签名的 bean 函数 void 作为返回类型 ActionEvent 对象作为参数 Bean 函数的示例如下
public void countListener(ActionEvent event) {}
评论