Popular use case is used in PF dialogs. This example is for both demonstration and testing.
Source
<p:growl id="growl" keepAlive="true">
<p:autoUpdate/>
</p:growl>
<h:panelGrid columns="6" id="pnlDetails" styleClass="p-4" >
<p:commandButton value="Open Dialog" type="button" icon="pi pi-external-link" onclick="PF('dlg').show()"/>
</h:panelGrid>
<p:dialog header="InputPhone" widgetVar="dlg" minHeight="40" width="60vw" showEffect="fade" closable="true" closeOnEscape="true" modal="true">
<pe:inputPhone id="txtPhone"
initialCountry="us"
value="#{basicInputPhoneController.phoneNumber}"
formatOnDisplay="true"
dir="ltr">
<p:ajax event="countrySelect" listener="#{basicInputPhoneController.onCountrySelect}" />
</pe:inputPhone>
</p:dialog>
@Named
@ViewScoped
public class BasicInputPhoneController implements Serializable {
private static final long serialVersionUID = 1L;
private String phoneNumber;
private Map<String, String> localizedCountries;
@PostConstruct
protected void init() {
localizedCountries = new HashMap<>();
localizedCountries.put("nl", "Nederland");
localizedCountries.put("be", "België");
localizedCountries.put("de", "Duitsland");
}
public void onCountrySelect(final SelectEvent<Country> event) {
final Country country = event.getObject();
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_WARN, "Selected " + country.getName(), null));
}
public void submit() {
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_INFO, "Phone Number " + phoneNumber, null));
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(final String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public Map<String, String> getLocalizedCountries() {
return localizedCountries;
}
}