How can I show/call a dialog programmatically and add this to stage (actual browser window)?
I want to trigger a database update every 2 hours. I have done this with a TimerTask. This works fine for me, the timer task gets all the data I want from the database. Before this timer task is triggered I want to “lock” the screen for some seconds that no user (session scoped) can access the database (I also know how this will work). My problem is that I don’t know/cannot find a way to call a dialog programmatically.
Update I want to set this primefaces dialog:
Dialog dialog = new Dialog();
dialog.setAppendToBody(true);
dialog.setModal(true);
dialog.setVisible(true);
dialog.setWidgetVar("generatedDialog");
dialog.setId("fancyDialog");
dialog.setClosable(false);
dialog.setHeader("Getting latest information from the database");
dialog.setDynamic(true);
dialog.setResizable(false);
dialog.setDraggable(false);
How can I display it to my browser?
You don’t need to create a dialog programatically. What you need is Push Technlogogy, i.e. the server initiates the interaction with the clients. PrimeFaces already have this technology and ready to use for you.
A basic case for your needs would be the PrimePush – FacesMessage:
/notificationschannel./notificationschannel, an action will be executed. In this case, the channel is only in the same page, and the action will be to show the notification.You can test this behavior by opening the same page in two different navigators and send a notification. All the pages will show the notification (and looks like what you want).
Having this example on, the only thing you need to do will be:
<p:dialog>.1 In order to prevent users to invoke this request for you, it would be good to set a Filter that prevents anyone except your timer to execute the request.