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?
<h:inputText id="postalCode" size="20" value="# businessPartner.primaryAddress.postalCode}"
<p:ajax event="change" listener="#{businessPartner.primaryAddress.retrievePostalCodeCity}" >
</p:ajax>
</h:inputText>
<h:inputText id="city" size="60" value="# businessPartner.primaryAddress.city}"
<p:ajax event="change" listener="#{businessPartner.primaryAddress.retrievePostalCodeCity}" >
</p:ajax>
</h:inputText>
public void retrievePostalCodeCity() throws MWSException {
int country = address.getCountryId();
String postalCode = address.getPostalCode();
String city = address.getCity();
}
I have this problem because I used to use a4j ajax, but I’m moving the project to fully primefaces and no longer richfaces. The listener to a4j has an AjaxBehaviorEvent event and there I could do event.getComponent().getId()
How can I do the same with prime ajax?
The
AjaxBehaviorEventis not specific to RichFaces. It’s specific to JSF2 itself. So you can just keep using it in PrimeFaces.As an alternative, or for the case that it’s really not possible elsewhere, you could always use the new JSF2
UIComponent#getCurrentComponent()method.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.