Dialog Framework provides APIs to pass and retrieve data between the source page and the dialog.
<div class="card">
<h:form>
<p:growl id="growl" showDetail="true"/>
<p:commandButton value="Select Product" icon="pi pi-home" action="#{dfView.chooseProduct}">
<p:ajax event="dialogReturn" listener="#{dfView.onProductChosen}" update="growl"/>
</p:commandButton>
</h:form>
</div>
@Named("dfView")
@RequestScoped
public class DFView {
public void viewProducts() {
Map<String, Object> options = new HashMap<>();
options.put("resizable", false);
PrimeFaces.current().dialog().openDynamic("viewProducts", options, null);
}
public void viewProductsCustomized() {
Map<String, Object> options = new HashMap<>();
options.put("modal", true);
options.put("width", 640);
options.put("height", 340);
options.put("contentWidth", "100%");
options.put("contentHeight", "100%");
options.put("headerElement", "customheader");
PrimeFaces.current().dialog().openDynamic("viewProducts", options, null);
}
public void chooseProduct() {
Map<String, Object> options = new HashMap<>();
options.put("resizable", false);
options.put("draggable", false);
options.put("modal", true);
PrimeFaces.current().dialog().openDynamic("selectProduct", options, null);
}
public void onProductChosen(SelectEvent event) {
Product product = (Product) event.getObject();
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Product Selected", "Name:" + product.getName());
FacesContext.getCurrentInstance().addMessage(null, message);
}
public void showMessage() {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Message", " Always Bet on Prime!");
PrimeFaces.current().dialog().showMessageDynamic(message);
}
}