59

I've searched the Internet and I cannot find a list of <p:ajax> events. Can anyone provide a complete list of events for the <p:ajax> tag?

I'm particularly interested if there is an onblur event or something similar.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Catfish
  • 18,876
  • 54
  • 209
  • 353

7 Answers7

45

You might want to look at "JavaScript HTML DOM Events" for a general overview of events:

http://www.w3schools.com/jsref/dom_obj_event.asp

PrimeFaces is built on jQuery, so here's jQuery's "Events" documentation:

http://api.jquery.com/category/events/

http://api.jquery.com/category/events/form-events/

http://api.jquery.com/category/events/keyboard-events/

http://api.jquery.com/category/events/mouse-events/

http://api.jquery.com/category/events/browser-events/

Below, I've listed some of the more common events, with comments about where they can be used (taken from jQuery documentation).

Mouse Events

(Any HTML element can receive these events.)

click

dblclick

mousedown

mousemove

mouseover

mouseout

mouseup

Keyboard Events

(These events can be attached to any element, but the event is only sent to the element that has the focus. Focusable elements can vary between browsers, but form elements can always get focus so are reasonable candidates for these event types.)

keydown

keypress

keyup

Form Events

blur (In recent browsers, the domain of the event has been extended to include all element types.)

change (This event is limited to <input> elements, <textarea> boxes and <select> elements.)

focus (This event is implicitly applicable to a limited set of elements, such as form elements (<input>, <select>, etc.) and links (<a href>). In recent browser versions, the event can be extended to include all element types by explicitly setting the element's tabindex property. An element can gain focus via keyboard commands, such as the Tab key, or by mouse clicks on the element.)

select (This event is limited to <input type="text"> fields and <textarea> boxes.)

submit (It can only be attached to <form> elements.)

Nick Humphrey
  • 611
  • 6
  • 15
41

You can search for "Ajax Behavior Events" in PrimeFaces User's Guide, and you will find plenty of them for all supported components. That's also what PrimeFaces lead Optimus Prime suggest to do in this related question at the PrimeFaces forum <p:ajax> event list?

There is no onblur event, that's the HTML attribute name, but there is a blur event. It's just without the "on" prefix like as the HTML attribute name. You can also look at all "on*" attributes of the tag documentation of the component in question to see which are all available, e.g. <p:inputText>.

mrBen
  • 276
  • 1
  • 5
  • 15
Daniel
  • 36,833
  • 10
  • 119
  • 200
  • 15
    The documentation doesn't list the events for the p:ajax tag. I would also expect to have a list of p:ajax events listed on the web somewhere. I wouldn't think i'd have to dig through the source to find such a thing. It'd be nice if someone could just post all of the possibilities here so that when the next guy searches for it he'll find them. The link on the inputText tag is useful, but i'm not sure if that is ALL of the possible events. If it is i'd like to post it here. – Catfish Jul 20 '12 at 21:34
  • 6
    Every component has a different set of custom p:ajax event, you need to refer to each section in user's guide and look for ajax behavior events. All there in guide. Non-custom events like, click, keyup are not documented as it is general knowledge of dom events. – Cagatay Civici Jul 22 '12 at 10:24
  • 2
    Contrary to previous comment, the user's guide I have (3.4) doesn't *have* a section listing this. – ClioCJS Mar 27 '13 at 15:14
  • 1
    @ClintJCL , just do search inside the *Ajax Behavior Events* text in the pdf , you will find plenty of them... (in http://primefaces.googlecode.com/files/primefaces_users_guide_3_4.pdf) – Daniel Mar 27 '13 at 16:14
  • 3
    Yes, you will find SOME events, but only special events for some special components like Schedule or SelectCheckBoxMenu. You won't find what is supported for i.e. InputText – NeplatnyUdaj Dec 09 '13 at 11:48
  • I'm sorry, but it doesn't answer the question. What version of User's Guide? Obviously not the 3.5 one. There are **some** events described for **some** component, but there's no way to learn what events to register from that resource! – Danubian Sailor Feb 07 '14 at 08:42
  • @ŁukaszL. It is answering the q' and if there are missing events in the docs its a bug of primefaces and you should report it to them instead of down voting an answer... As a proof you can see the comment of Cagatay Civici that approve this answer as the right one – Daniel Feb 09 '14 at 07:15
  • 1
    This question does answer it. What you have to do is go to the tag documentation, find the component you use AJAX on and have a look what events it has. For example you use ajax on inputText. Then find inputText component and you can clearly see it has some events like blur, onmouseout, onkeyup and much more. Those are the keywords you can type into . Documentation link is http://www.primefaces.org/docs/vdl/3.4/ –  Mar 09 '14 at 09:36
  • 2
    **except** for the fact that quite a lot of components are composite components - for example : `autoComplete` also is `inputText` ... which seems kinda obvious **but** it forces developers to assemble documentation snippets from multiple places ... which is bullshit. The entire documentation is confusing and seems arbitrary, this is not a real answer, its basically equal to *"RTFM but its bad and you will waste time, now give me SO rep for literally nothing"*. – specializt May 30 '16 at 11:54
  • TL;DR: Look at the PrimeFaces documentation for the component in question and look for all the _onXXXX_ attributes. – jahroy Mar 02 '21 at 17:10
14

Schedule provides various ajax behavior events to respond user actions.

  • "dateSelect" org.primefaces.event.SelectEvent When a date is selected.
  • "eventSelect" org.primefaces.event.SelectEvent When an event is selected.
  • "eventMove" org.primefaces.event.ScheduleEntryMoveEvent When an event is moved.
  • "eventResize" org.primefaces.event.ScheduleEntryResizeEvent When an event is resized.
  • "viewChange" org.primefaces.event.SelectEvent When a view is changed.
  • "toggleSelect" org.primefaces.event.ToggleSelectEvent When toggle all checkbox changes
  • "expand" org.primefaces.event.NodeExpandEvent When a node is expanded.
  • "collapse" org.primefaces.event.NodeCollapseEvent When a node is collapsed.
  • "select" org.primefaces.event.NodeSelectEvent When a node is selected.-
  • "collapse" org.primefaces.event.NodeUnselectEvent When a node is unselected
  • "expand org.primefaces.event.NodeExpandEvent When a node is expanded.
  • "unselect" org.primefaces.event.NodeUnselectEvent When a node is unselected.
  • "colResize" org.primefaces.event.ColumnResizeEvent When a column is resized
  • "page" org.primefaces.event.data.PageEvent On pagination.
  • "sort" org.primefaces.event.data.SortEvent When a column is sorted.
  • "filter" org.primefaces.event.data.FilterEvent On filtering.
  • "rowSelect" org.primefaces.event.SelectEvent When a row is being selected.
  • "rowUnselect" org.primefaces.event.UnselectEvent When a row is being unselected.
  • "rowEdit" org.primefaces.event.RowEditEvent When a row is edited.
  • "rowEditInit" org.primefaces.event.RowEditEvent When a row switches to edit mode
  • "rowEditCancel" org.primefaces.event.RowEditEvent When row edit is cancelled.
  • "colResize" org.primefaces.event.ColumnResizeEvent When a column is being selected.
  • "toggleSelect" org.primefaces.event.ToggleSelectEvent When header checkbox is toggled.
  • "colReorder" - When columns are reordered.
  • "rowSelectRadio" org.primefaces.event.SelectEvent Row selection with radio.
  • "rowSelectCheckbox" org.primefaces.event.SelectEvent Row selection with checkbox.
  • "rowUnselectCheckbox" org.primefaces.event.UnselectEvent Row unselection with checkbox.
  • "rowDblselect" org.primefaces.event.SelectEvent Row selection with double click.
  • "rowToggle" org.primefaces.event.ToggleEvent Row expand or collapse.
  • "contextMenu" org.primefaces.event.SelectEvent ContextMenu display.
  • "cellEdit" org.primefaces.event.CellEditEvent When a cell is edited.
  • "rowReorder" org.primefaces.event.ReorderEvent On row reorder.

there is more in here https://www.primefaces.org/docs/guide/primefaces_user_guide_5_0.pdf

cнŝdk
  • 31,391
  • 7
  • 56
  • 78
Boris_Ndong
  • 247
  • 2
  • 4
  • 1
    PLEASE PLEASE PLEASE Refer to a more recent version of the docs – Kukeltje Nov 06 '17 at 18:43
  • There are still plenty of people using previous versions sir ! ! ! You can't just think of yourself – Boris_Ndong Nov 06 '17 at 20:17
  • I'm using 5.0(.x) AND 6.1, but it is meant in general... I never stated to replace it... Adding it is good too. Unless questions are specific for a version it is always best to add at least the latest. And if you post a list, try to make it complete (you seem to know there is more in the docs, why did you not mention them?) – Kukeltje Nov 06 '17 at 23:18
  • Thanks for the answer! Just what I was looking for. – A.Alessio May 15 '20 at 16:47
9

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:

<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]

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

<p:ajax event="itemSelect" listener="#{anyBean.onItemSelect}"/>

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.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Selaron
  • 6,105
  • 4
  • 31
  • 39
6

Unfortunatelly, Ajax events are poorly documented and I haven't found any comprehensive list. For example, User Guide v. 3.5 lists itemChange event for p:autoComplete, but forgets to mention change event.

If you want to find out which events are supported:

  1. Download and unpack primefaces source jar
  2. Find the JavaScript file, where your component is defined (for example, most form components such as SelectOneMenu are defined in forms.js)
  3. Search for this.cfg.behaviors references

For example, this section is responsible for launching toggleSelect event in SelectCheckboxMenu 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);
    }
},
Danubian Sailor
  • 1
  • 38
  • 145
  • 223
3

I've got the list in debug mode; first I saw the point at which the error was thrown

javax.faces.view.facelets.TagException: /showcase/partial_submit.xhtml @26,36 Event:changed is not supported. org.primefaces.component.behavior.ajax.AjaxBehaviorHandler.applyAttachedObject(AjaxBehaviorHandler.java:179) org.primefaces.component.behavior.ajax.AjaxBehaviorHandler.apply(AjaxBehaviorHandler.java:157)

and then I debugged AjaxBehaviorHandler

enter image description here

so if you want discover the right list of supported event, you can generate an error (using an event name that is wrong), and follow this way

Frizz1977
  • 1,121
  • 13
  • 21
1

Here's what I found during debug.

enter image description here

Twinkle_Monkey
  • 185
  • 1
  • 4
  • 14