Primefaces : Ajax Call Inside p:dialog is not working

冷暖自知 提交于 2019-12-25 08:15:50

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/10027751/primefaces-ajax-call-inside-pdialog-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!