1

我将遗留项目转换为更现代的库版本。旧版本使用以下ajax4jsf代码:

HtmlAjaxCommandLink link = new HtmlAjaxCommandLink()
link.addAjaxListener(new AjaxListener() {
    @Override
    public void processAjax(AjaxEvent event) { }
});

根据文档,HtmlAjaxCommandLink在 Richfaces 4 中被 UICommandLink 取代

不过,我似乎无法很好地替换控件的addAjaxListener

可以用什么代替?

4

1 回答 1

4

自 JSF2 以来,ajax 已被 JSF API 标准化。所有支持客户端行为的组件都应该实现ClientBehaviorHolder,这反过来又提供了addClientBehavior()添加客户端行为的方法。ajax 的具体客户端行为实现是AjaxBehavior反过来提供addAjaxBehaviorListener()正是您正在寻找的方法。

总而言之,在您的特定情况下,可以将其替换如下:

UICommandLink link = new UICommandLink(); // Note: you can also just use standard JSF HtmlCommandLink.
link.setId("linkId"); // Fixed ID is mandatory for successful processing.
link.setValue("click here"); // Not sure if you need it. Just to be complete.
AjaxBehavior ajaxAction = new AjaxBehavior();
ajaxAction.addAjaxBehaviorListener(new AjaxBehaviorListener() {
    @Override
    public void processAjaxBehavior(AjaxBehaviorEvent event) throws AbortProcessingException {
        System.out.println("Ajax behavior listener invoked."); // Do your actual job jere.
    }
});
link.addClientBehavior("action", ajaxAction); // Note: don't use "click" event!
于 2013-02-19T19:34:00.940 回答