0

In my project I am using f:ajax listener with arguments like this:

    <h:inputText value="#{myBean.person.name}">
        <f:ajax 
            event="change" 
            listener="#{myBean.doSomething(myBean.person.id)}" />
    </h:inputText>  

with a listener in MyBean

    public void doSomething(Integer id)
    {
        // do something with id ...
    }

The Oracle Documentation f:ajax says that the signature of the listener for f:ajax must match the following:

public void processAjaxBehavior(javax.faces.event.AjaxBehaviorEvent event) throws javax.faces.event.AbortProcessingException) 

So according to the Oracle Documentation it should be done like this:

    <h:inputText value="#{myBean.person.name}">
        <f:attribute  
            name="identifier" 
            value="#{myBean.id}"/>
        <f:ajax 
            event="change" 
            listener="#{myBean.doSomething}" />
    </h:inputText>  

with a listener in MyBean

    public void doSomething(AjaxBehaviorEvent event) throws AbortProcessingException
    {
        Integer id = (Integer) event.getComponent().getAttributes().get("identifier");
        // do something with id ...
    }

Both examples work in my application. But the first example is very intuitive and more easy to use.

Are there arguments against using the listener with parameters other than AjaxBehaviorEvent?

Gio
  • 631
  • 6
  • 11
  • Does this answer your question? [Send additional parameter to Ajax event listener](https://stackoverflow.com/questions/39143601/send-additional-parameter-to-ajax-event-listener) – Jasper de Vries Feb 03 '22 at 12:34
  • This question is talking about primefaces. I use standard JSF only. Of course I can use the – Gio Feb 03 '22 at 17:34
  • It's no matter of should or shouldn't, it's can or cannot. You'll need a different way of passing properties to the listener. – Jasper de Vries Feb 06 '22 at 15:55

0 Answers0