I have multiple input field with a p:ajax with a listener. They all connect to the same listener. How can I know what component triggerd the listener?
The AjaxBehaviorEvent is not specific to RichFaces. It's specific to JSF2 itself. So you can just keep using it in PrimeFaces.
public void retrievePostalCodeCity(AjaxBehaviorEvent event) {
UIComponent component = event.getComponent();
// ...
}
As an alternative, or for the case that it's really not possible elsewhere, you could always use the new JSF2 UIComponent#getCurrentComponent() method.
public void retrievePostalCodeCity() {
UIComponent component = UIComponent.getCurrentComponent(FacesContext.getCurrentInstance());
// ...
}
By the way, the very same construct should work just fine with JSF2's own <f:ajax>
. I do not see any reason to use <p:ajax>
here. It would however be the only way if you were actually using a PrimeFaces component such as <p:inputText>
.
Unrelated to the concrete problem, the event="change"
is the default already. You can just omit it.
It is almost same in primefaces:
<p:ajax event="change" listener="#{businessPartner.primaryAddress.retrievePostalCodeCity}" />
import javax.faces.event.AjaxBehaviorEvent;
.....
public void retrievePostalCodeCity(AjaxBehaviorEvent event) {
...
}
If you want to access via button component action/actionListener tag you can use ActionEvent
and for any case make sure you set ajax="true":
<p:commandLink actionListener="#{businessPartner.primaryAddress.retrievePostalCodeCity}" ajax="true" />
import javax.faces.event.ActionEvent;
....
public void retrievePostalCodeCity(ActionEvent event) {
...
}