jsf ajax event,jsf - List of <p:ajax> events - Stack Overflow

本文介绍了如何确定JSF组件支持的Ajax事件。可以通过在XHTML中绑定组件并打印事件Names属性,或者在Java代码中调用UIComponentBase的getEventNames()方法来获取事件列表。此外,查阅组件的官方文档是获取事件及其详细描述的最佳方式,例如PrimeFaces组件的文档。当文档中未明确列出Ajax事件时,可以参考JavaScript回调函数名称来确定事件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

As the list of possible events is not tied to p:ajax itself but to the component it is used with, you'll have to ask the component for which ajax events it supports.

There are multiple ways to determine the ajax events for a given component:

1) Ask the component in xhtml:

You can output the list directly in xhtml by binding that component to a request scoped variable and printing the eventNames property:

This outputs

[blur, change, valueChange, click, dblclick, focus, keydown, keypress, keyup,

mousedown, mousemove, mouseout, mouseover, mouseup, select, itemSelect,

itemUnselect, query, moreText, clear]

2) Ask the component in java code:

Figure out the component implementation class and invoke its' implementation of javax.faces.component.UIComponentBase.getEventNames() method:

import javax.faces.component.UIComponentBase;

public class SomeTest {

public static void main(String[] args) {

dumpEvents(new org.primefaces.component.inputtext.InputText());

dumpEvents(new org.primefaces.component.autocomplete.AutoComplete());

dumpEvents(new org.primefaces.component.datatable.DataTable());

}

private static void dumpEvents(UIComponentBase comp) {

System.out.println(

comp + ":\n\tdefaultEvent: " + comp.getDefaultEventName() + ";\n\tEvents: " + comp.getEventNames());

}

}

This outputs:

org.primefaces.component.inputtext.InputText@239963d8:

defaultEvent: valueChange;

Events: [blur, change, valueChange, click, dblclick, focus, keydown, keypress, keyup, mousedown, mousemove, mouseout, mouseover, mouseup, select]

org.primefaces.component.autocomplete.AutoComplete@72d818d1:

defaultEvent: valueChange;

Events: [blur, change, valueChange, click, dblclick, focus, keydown, keypress, keyup, mousedown, mousemove, mouseout, mouseover, mouseup, select, itemSelect, itemUnselect, query, moreText, clear]

org.primefaces.component.datatable.DataTable@614ddd49:

defaultEvent: null;

Events: [rowUnselect, colReorder, tap, rowEditInit, toggleSelect, cellEditInit, sort, rowToggle, cellEdit, rowSelectRadio, filter, cellEditCancel, rowSelect, contextMenu, taphold, rowReorder, colResize, rowUnselectCheckbox, rowDblselect, rowEdit, page, rowEditCancel, virtualScroll, rowSelectCheckbox]

3) 'rtfm' ;-)

Best option is to look into the documentation of the particular component in use as hopefully provided by the component developers, not limited to PrimeFaces btw. (p:ajax can be attached to any component providing ajax behaviors).

The advantage over previous suggestions is that the documentation not only provides the event names, but also enhanced description of the event potentially enriched with an event type class that can be caught by a listener.

For example the org.primefaces.event.SelectEvent in case of

and listener method signature public void onItemSelect(SelectEvent) provides additional event contextual data.

Where there is no explicit list of ajax events on a compoment in the PrimeFaces documentation, the list of on* javascript callbacks can be used as events by removing the 'on' and using the remainder as an event name. The other answers in this question provides help on these plain dom events too.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值