0

I have a web application, which is an implementation of the Front Controller Pattern, as described by the image below. Specifically, I have followed the code example of the Front Controller Pattern, as described in this question's answer:

Design Patterns web based applications

Front Controller

I'm having updating issues with one of my .jsp pages. This page in particular has a popup-editor, which allows the user to add or remove links to sets of data from an external database. If the user hits a save-button, it sends a request, which is intercepted by the Front Controller. Then, the correct action for saving or deleting a reference link (many to many ID numbers) is executed on the systems own database. After, the page should be reloaded, which triggers a chained command, which loads data from both databases, before redirecting to essentially the same page, without the popup.

However, the page is not reloaded, due to some form of caching that I do not understand. I've tried every solution I could find, to prevent loading cached data, from adding a unique value to the URL, to adding meta-tags on the jsp-page, to prevent it from caching at all. I've confirmed that the data is loading on server side. A simple F5-click updates the page like it should be doing automatically.

I've also implemented an onClose-function on the popup, that calls a window.location.reload(). However this call interrupts the Front Controller, and it stops everything it is currently doing, to handle the newest request. This creates a race condition, where the data is sometimes able to be inserted/deleted, and sometimes not, before the Front Controller starts reloading the page.

Should I make a queue? Is there a good reason not to do it this way? Should the Front controller's execution method, or the class itself implement some kind of Synchronization?

Community
  • 1
  • 1
jumps4fun
  • 3,994
  • 10
  • 50
  • 96

1 Answers1

0

Your popup-editor should be placed inside an iframe so that it will not reload the window when it submits. The response that returns from request sent by the iframe should trigger the window.location.reload(). For example:

<html>
  <script type='text/javascript'>
    window.onload = function() {
      window.location.reload();
    };
  </script>
</html>

Another option is to send the update with an Ajax call and then reload the page when the Ajax call returns. Or nicer, update the page dynamically without a reload but with JSON data returned by the Ajax call.

  • Line-by-Line response: My popup-editor does not automatically reload the parent window when submitting. I have implemented that manually, as it is the only reload function I have been able to make work. I've tried to pass variables back to the browser, that should've triggered a page reload, but I couldn't make it work. Also, that would trigger the server side loading of the data twice, which results in poor performance, so I'd rather figure out why the server side data is not displayed correct the first time (caching?). – jumps4fun Jul 10 '14 at 10:30
  • I think the second half of your answer is definitely something to consider. it would just be so much easier to implement something that would stabilize my current attempts. The Ajax-solution makes me work in areas where my experience is limited, and I fear that a similar small bug might appear there, and I have restructured my code for no reason. Still, I am very close to the point where I am ready to give up on my current attempts, and just go for an Ajax-solution... – jumps4fun Jul 10 '14 at 10:36
  • You should make your popup-editor only reload the page once it has received the response from the server, otherwise it will interrupt the request. This way you will know the data has been updated on the server side before reloading the window. The server response could for example contain only the javascript reload call. Basically an empty page with only the javascript window.location.reload() call in the body. The response will then be very lightweight and from a user perspective it will seem that the window is reloaded right after the popup submit. – Arnaud Kleinveld Jul 10 '14 at 11:58
  • I definitely need to get a better understanding of the response. This seems to be the best advice out there for now, So i say a deepfelt Thank You, and accept your answer. :) – jumps4fun Jul 10 '14 at 13:48
  • Taking the Front Controller Pattern, the HTTP response from the server received by the browser inside the popup iframe will contain the view that was returned by the action. That view only has to contain a javascript reload call, with the proper HTML tagging of course. – Arnaud Kleinveld Jul 10 '14 at 14:09
  • I've realized that my weakness has been a lack of understanding of the response, and my efforts to learn more about how it really works, has really paid off. My code is getting a lot more robust, and I am removing the possibilities of race contidions, by making sure I have control of the sequencing. I have made a lot of workarounds in my project, so that I have avoided actually having to do anything manually with the response object. It has been working up until this point, but I feel a lot more confident in my code now. It's a whole new world out there ;) Thanks again. – jumps4fun Jul 11 '14 at 14:08