Proper handling for browser page refresh

I’m stuck with the situation when I need to close modal window each time user hits “refresh” button of the web browser. In a word, I have an application which has main window displaying some status information and wizard to set application parameters (opened in modal window and using TPTMultiView). I need to handle situations when user refreshes the page or navigates away/returns back when modal window is opened - specifically, need to close modal window in this case (and subsequently discard all changes made by user). Currently when I refresh the page - modal window is still opened and displayed in left-upper corner of the page.

Initial idea was to implement HttpRequestListener and remove all windows except main one on each request start. However this was just not working at all. As I see many people on this forum had problems related to this, but I can’t find any straightforward solution yet. Which is strange since task seems to be really basic…

Can someone point me to solution or at least workaround for this?



UPDATE

Found a workaround:

  1. Use parameter in URL to access the application, i.e. http://localhost:8080/app?refresh=1.
  2. Create ParameterHandler class:

public class MyParameterHandler implements ParameterHandler 
{
	public void handleParameters(Map<String, String[]> parameters) 
	{
		String[] valueArray = parameters.get("refresh");
		if(null != valueArray && 0 < valueArray.length)
		{
			TPTApplication.getCurrentApplication().close();
		}        
	}
}

In this case each browser page refresh will result in new Application instance.

However, I’m still not sure if this is the only way or I’ve missed something. This way is also applicable to rather small applications only and also doesn’t handle any “partial” refresh. I.e. what if I need some state info to be preserved and some other portion cleared?..