15

Is it possible to have multiple events in the same p:ajax?

Something like this:

<p:ajax event="firstEvent,secondEvent..." listener="doSomething();" />
waickem
  • 161
  • 1
  • 1
  • 7
  • 2
    Three letters... T R Y... (and 'doSomething();' will never work. If you create pseudo code, do it at least a little better ;-)) – Kukeltje Feb 03 '16 at 16:20
  • 2
    Hey thanks, but the point here was to show the definition of event defining or what I mean. Of course, who did try this has found it doesn't work. The question is about the existence of some form of naming like in this pseudo-code. Sorry if I was not enough clear. – waickem Feb 04 '16 at 18:12
  • Well, if it does not work and you don't find any documentation about this, tge only thing you can do is try with a different plain jsf example. If it does not work there either, it just might be that it is not supported. The specs of jsf are open btw – Kukeltje Feb 04 '16 at 19:56
  • I know I'm late to the party, but it seems that's not possible: https://forum.primefaces.org/viewtopic.php?p=8902#p8902 – Nakarukatoshi Uzumaki Sep 13 '21 at 07:14

2 Answers2

11

I know it's late, but I found a way to do this. You only need to put N tags of p:ajax, i.e:

<p:calendar id="startDate" value="#{bean.date}"
    pattern="dd.MM.yyyy"
    validator="#{bean.checkDate}">
    <p:ajax update="dialog:endDate" event="dateSelect" /> 
    <p:ajax update="dialog:endDate" event="keyup" /> 
</p:calendar>
Matze
  • 361
  • 4
  • 9
joseluiselp
  • 172
  • 1
  • 12
  • 3
    The question: _"Multiple events in the **same p:ajax** in PrimeFaces"_. Your answer is the normal way and yes, sure that will work. The question was about doing it a completely different way with using just one `p:ajax` tag – Kukeltje Jul 12 '16 at 07:12
  • 2
    It's a useful answer. – K.Nicholas Jul 20 '17 at 21:16
  • I just wanted confirmation - and that helped me. You know, separate by space, colon, comma, ... just had to be sure it was not possible. – YoYo Jan 08 '19 at 03:13
3

Faced with the same problem and came across this post. After trivial investigation, the "multiple events in the same p:ajax"-approach will not work. It is not supported at least for the tested Primefaces 5.3 version. An Exception like this will arise:

javax.faces.view.facelets.TagException: <p:ajax> Event:firstEvent,secondEvent is not supported.

Some source code from the AbstractBehaviorHandler class:

 ClientBehaviorHolder holder = (ClientBehaviorHolder) parent;

    String eventName = getEventName();

    if (null == eventName) {
        eventName = holder.getDefaultEventName();
        if (null == eventName) {
            throw new TagException(this.tag, "Event attribute could not be determined: "  + eventName);
        }
    } else {
        Collection<String> eventNames = holder.getEventNames();
        if (!eventNames.contains(eventName)) {
            throw new TagException(this.tag,  "Event:" + eventName + " is not supported.");
        }
    }
olexd
  • 1,360
  • 3
  • 13
  • 26