I open a Dialog using Primefaces dialog framework
RequestContext.getCurrentInstance().openDialog("myDialog", options, null);
Then, I want to update a component in the base page after the dialog's close event. I know we could add a 'dialogReturn' ajax event
<p:ajax event="dialogReturn" update = ":form:colors" />
But how to do this programmatically using the dialog framework?
hope that my answer could help.
[Important] Scenario
First, I define an XHTML page (my dialog) to show products that are not in showcase of our shop and we can add products by this dialog, and in another hand, we have a page that presents all products already on the showcase, and we need to update it automatically, after close the dialog.
First, we create the main page that shows products already on the case, like:
File
showcase.xhtml
The most important fragment of this page is:
This part of the code has two main, first: open the dialog by the method
showCaseBean.addProductToShowCase()
and make an ajax call after close the dialog, and the method to be executed isshowCaseBean.afterCloseDialog(SelectEvent)
My
showCaseBean.java
:add_product_to_showcase_dialog.xhtml
has all products that are not in ShowCase and we add it.The most critical part right here is the button that closes our form, other parts are only contextual and not critical at all
Where we simple close the dialog, through code in the bean.
Let's see the class
AddProductToShowCaseDialogBean.java
After we click on the button and close our dialog, the ajax callback in ShowCaseBean is called and we reload the products on the showcase by the method afterCloseDialog and we update the table with the ID product-table
Those tutorials in PrimeFaces Doc helped me to solve the problem, you can check it also:
https://primefaces.github.io/primefaces/8_0/#/core/dialogframework https://www.primefaces.org/showcase-v8/ui/df/data.xhtml
Don't forget to upvote the answer, to help others if helped you