Apparently like others have experienced, I've found it a bit of a challenge to determine exactly what ajax events are supported by Primefaces components. There is a helpful stackoverflow thread that I've encountered more than once that gives some useful suggestions, and I wanted to list some of them here in case the thread disappears.
The first place to look, of course, is the Primefaces documentation for your version. The problem is that not all supported events are listed for all components. There is some helpful general information about DOM events on w3schools, and jQuery events.
One post suggests looking in the primefaces javascript code:
If you want to find out which events are supported:
If you want to find out which events are supported:
- Download and unpack primefaces source jar
- Find the JavaScript file, where your component is defined (for example, most form components such as
SelectOneMenu
are defined in forms.js)For example, this section is responsible for launching toggleSelect event in
- Search for
this.cfg.behaviors
referencesSelectCheckboxMenu
component:fireToggleSelectEvent: function(checked) {
if(this.cfg.behaviors) {
var toggleSelectBehavior = this.cfg.behaviors['toggleSelect'];
if(toggleSelectBehavior) {
var ext = {
params: [{name: this.id + '_checked', value: checked}]
}
}
toggleSelectBehavior.call(this, null, ext);
}
},
But the most interesting post gives mechanisms for listing the events in xhtml code and in java code.
The xhtml approach:
You can output the list directly in xhtml by binding that component to a request scoped variable and printing theeventNames
property:<p:autoComplete binding="#{ac}"></p:autoComplete>
<h:outputText value="#{ac.eventNames}" />
This outputs[blur, change, valueChange, click, dblclick, focus, keydown, keypress, keyup,
mousedown, mousemove, mouseout, mouseover, mouseup, select, itemSelect,
itemUnselect, query, moreText, clear]
The java approach:
Figure out the component implementation class and invoke its' implementation ofjavax.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]
No comments:
Post a Comment