jsfprimefacesprimefaces-datatable

How to check which primefaces ajax event triggered into java method


let's say we have two types of events that will be directed to the same method as mentioned in the below example

<p:ajax event="cellEdit" listener="#{bean.eventype}"/>
<p:ajax event="change" listener="#{bean.eventype}"/>

and here is the bean method for example

public void eventype(){
  println("");
}
  1. The question is, is it possible if I want to identify which value came from which events in eventype method?

  2. Is it possible to differentiate both mentioned events in eventype method?

Edited: I did try to add eventype(AjaxBehaviorEvent event) and use event.getSource() but it seems like am just getting the source details like org.inputtext.component@something.


Solution

  • The type of event is posted in the request in order for the component being able to decode it to trigger the correct event. The parameter name is javax.faces.behavior.event, which you can get like:

    String eventType = FacesContext.getCurrentInstance()
            .getExternalContext()
            .getRequestParameterMap()
            .get("javax.faces.behavior.event");
    

    This is implemented in PrimeFaces like:

    https://github.com/primefaces/primefaces/blob/042b5a14116cd4a279a114883a8575e0788494b8/primefaces/src/main/java/org/primefaces/util/ComponentUtils.java#L197-L224

    Note that you can also use the PrimeFaces constant Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM in your code instead of hardcoding "javax.faces.behavior.event".