Chirag Loliyana
Chirag Loliyana

Reputation: 17

Primefaces : Ajax Call Inside p:dialog is not working

I am trying to execute ajax method from Dialog, but its not getting executed.

<p:dialog header="Add Product" widgetVar="addProductDialog" modal="true" height="300" width="700" dynamic="true">

   <p:toolbar styleClass="toolBar">
      <p:toolbarGroup align="left">
         <p:commandButton styleClass="grn_actbttn" value="Cancel" onclick="addProductDialog.hide();" />
      </p:toolbarGroup>
      <p:toolbarGroup align="right">
         <p:commandButton styleClass="grn_actbttn" id="addproduct" value="Add Products" actionListener="#{customerProductsBean.saveCustomerProducts}"  oncomplete="addProductDialog.hide();" />
      </p:toolbarGroup>
   </p:toolbar>

</p:dialog>

Java Code

/**
 * Method used to save selected Customer Product from Add Product Dialog 
 * @param actionEvent
 */
public void saveCustomerProducts(ActionEvent actionEvent) {

// DB call to save to database

}

Is it like that p:dialog doesn't support AJAX call ?

Upvotes: 0

Views: 8320

Answers (1)

maple_shaft
maple_shaft

Reputation: 10463

Your dialog is being moved out of the form after it is rendered on the page. This is a side-effect of the way the client side widgets work for Primefaces dialogs.

Adding appendToBody="true" attribute to dialog will generally fix this.

If this doesn't work then make sure that your dialog is not surrounded by a form, but instead put a form element inside the dialog.

Upvotes: 3

Related Questions