PrimeFaces Ajax ActionListener

2025 年 3 月 17 日 | 阅读 1 分钟

它用于通过触发操作来调用 Java 方法。此操作既可以使用 commandButton 也可以使用 commandLink 完成。在这里,我们正在创建一个示例,该示例调用 ManagedBean 的一个方法,每次单击该按钮时,当前值都会使用 Ajax 进行更新。

此示例包括以下文件。

JSF 文件

// actionListener.xhtml

托管 Bean

// AjaxCounter.java

输出

PrimeFaces Actionlistener example 1

单击 commandButton 后,它会调用该方法并将计数器增加 2。

PrimeFaces Actionlistener example 2