PrimeFaces - Passing data from Dialog to Source Page by using dialogReturn event

[Updated: Dec 12, 2017, Created: Dec 12, 2017]

Following example shows how to pass data from a page displayed in the dialog (opened via openDialog()) back to the parent page by using 'dialogReturn' ajax behavior event.


Parent JSF page


    <h2>PrimeFaces - Programmatic Dialog</h2>
        <p:commandButton value="Show Employees" actionListener="#{mainBean.showEmployees}">
            <p:ajax event="dialogReturn" listener="#{mainBean.onEmployeeSelected}" update="selectedEmpPanel" />
        <h3>Selected Employees:</h3>
        <h:panelGrid id="selectedEmpPanel" columns="1">
            <ui:repeat value="#{mainBean.selectedEmployees}" var="emp">
                <h:outputText value="#{} (#{emp.department})"/>

The Main bean

public class MainBean {
  private List<Employee> selectedEmployees = new ArrayList<>();

  public void showEmployees(ActionEvent ae) {
                    .openDialog("employee", getDialogOptions(), null);

  public Map<String, Object> getDialogOptions() {
      Map<String, Object> options = new HashMap<>();
      options.put("resizable", false);
      options.put("draggable", true);
      options.put("modal", true);
      options.put("height", 600);
      options.put("contentHeight", "100%");
      return options;

  public void onEmployeeSelected(SelectEvent selectEvent) {
      this.selectedEmployees = (List<Employee>) selectEvent.getObject();

  public List<Employee> getSelectedEmployees() {
      return selectedEmployees;
public class Employee {
  private long id;
  private String name;
  private String phoneNumber;
  private String department;

The Employee Page


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns=""
        <p:dataTable var="employee"
            <p:column headerText="Id">
                <h:outputText value="#{}"/>

            <p:column headerText="Name">
                <h:outputText value="#{}"/>

            <p:column headerText="Phone Number">
                <h:outputText value="#{employee.phoneNumber}"/>

            <p:column headerText="Department">
                <h:outputText value="#{employee.department}"/>
            <p:column selectionMode="multiple"
        <f:facet name="footer">
            <p:commandButton value="Submit" actionListener="#{employeeBean.submitSelectedEmployees()}"/>

The Employee bean

public class EmployeeBean {
  private List<Employee> selectedEmployees;

  public List<Employee> getEmployeeList() {
      return EmployeeService.Instance.getEmployees();

  public List<Employee> getSelectedEmployees() {
      return selectedEmployees;

  public void setSelectedEmployees(List<Employee> selectedEmployees) {
      this.selectedEmployees = selectedEmployees;

  public void submitSelectedEmployees() {

To try examples, run embedded tomcat (configured in pom.xml of example project below):

mvn tomcat7:run-war


Main page:

Invoking dialog by clicking 'Show Employees' button and making selections by clicking checkboxes:

On Submitting the dialog:

Example Project

Dependencies and Technologies Used :

  • primefaces 6.1 primefaces
  • jsf-api 2.2.14: This is the master POM file for Oracle's Implementation of the JSF 2.2 Specification.
  • jsf-impl 2.2.14: This is the master POM file for Oracle's Implementation of the JSF 2.2 Specification.
  • datafactory 0.8: Library to generate data for testing.
  • JDK 1.8
  • Maven 3.3.9

Sending Data From Dialog to the Parent Page Example Select All Download
  • dialog-return-example
    • src
      • main
        • java
          • com
            • logicbig
              • example
        • webapp
          • WEB-INF

See Also