I am adding some value to database in jsf. I have a manage bean for this purpose. Now when insertion is successful then I want to show a success alert dialog. please tell me how to do it?
Asked
Active
Viewed 999 times
-8
-
What have you already tried? – Aritz Mar 21 '15 at 10:41
-
Use https://stackoverflow.com/questions/9195756/keep-pdialog-open-when-a-validation-error-occurs-after-submit and be creative – Kukeltje Jul 17 '18 at 06:47
1 Answers
0
I would suggest to add a dialog component in your page (the same page that calls your bean to insert a value into the DB for instance)
p:dialog id="dialog" widgetVar="widgetVarOfDialog"
Then let assume that you have either a commandButton
or a commandLink
(you don't provide enough information in your first post) that triggers the insert action in your bean. Just add an oncomplete callback:
p:commandButton action="#{bean.insertValue}" oncomplete="PF('widgetVarOfDialog').show()"
You could also display a p:dialog
right from your bean method by using:
RequestContext context = RequestContext.getCurrentInstance();
context.execute("PF('widgetVarOfDialog').show()");

Mathieu Castets
- 5,861
- 3
- 28
- 37
-
Seems to me the dialog will be shown no matter if the insert was not succesful – Jaqen H'ghar Mar 22 '15 at 15:46
-
Yeah but, as the original question is too vague, I provided a generic solution. Use the programmatic way to display the dialog based on the insert return status or add a context parameter which can be processed in the oncomplete event. – Mathieu Castets Mar 22 '15 at 17:55
-
Use parts from https://stackoverflow.com/questions/9195756/keep-pdialog-open-when-a-validation-error-occurs-after-submit – Kukeltje Jul 17 '18 at 06:48