In the web application is mostly one-way communication – Browser send request, server receives it and response. This means
- If we don’t use a special technologies like a Web Sockets, that there is no way for server to communicate tho the browser
- Also if we don’t really know where is the user and if he still will interact with us.
So here we have 2 major questions:
- How to return control to user when server logic needs it?
- Prevent data further data modifications? For example if dialog is required when user clicked save.
In Acumatica we have solved these problems with exceptions. When we need to rise a message, we just simple throw a special type of exception, that prevents operation from execution and return control back to user.
After user respond, we can repeat the same call and pass there a dialog answer.
The diagram above briefly explains how does it work:
- User Triggers Action
- Browser sends request to the Acumatica sever
- Acumatica server identifies that we need to show dialog and throw an exception
- Acumatica core gets this exception and return a special response back to browser.
- Browser shows dialog and waits for user reply
- Reply sends back to Acumatica with the previous data, so we can repeat operation
- Acumatica server completes the operation.
In Acumatica we have a lot of exceptions like this:
- PXRedirectRequiredException – redirects user to the different screen
- PXPopupRedirectException – shows different screen as a popup
- PXReportRequiredException – redirects user to the different report
- PXRedirectWithReportException – this is combination of first and third exceptions – it can an redirect and open a report together
- PXRedirectToUrlException – redirects user to the 3rd party url.
- PXDialogRequiredException – shows a dialog with questions/answer
- PXRefreshException – simple refreshes the current screen. Useful when settings are changed.
Hope it helps!