struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeromy Evans <jeromy.ev...@blueskyminds.com.au>
Subject Re: Struts2 + Dojo 0.4 + unbeforeunload problem
Date Fri, 12 Sep 2008 07:50:23 GMT
I don't really know as i don't use dojo or the ajax tags for any more 
for all the same reasons you're experiencing.

Dojo's event model is based on AOP concepts; which allows you to bind 
functions to the event, before the event or after the event.
So you need a listener attached to before the unload event and tell it 
to not proceed with the default operation...somehow...

If this was native javascript you'd simply call event.preventDefault()

Related example:
ie. So, if you were doing a confirm for a submit, the submit button 
would publish a topic (/submit)
You attach a listener to the before /submit topic
It prompts "Are you sure?"
If they say no, you cancel the event by setting the event.cancel flag.

In the case of a beforeunload event caught via dojo...not sure.  But if 
you can get the listener invoked by dojo, then either the scope (this) 
or the argument (event) will reference an event object that probably has 
the cancel flag.

Otherwise you could try a e.preventDefault using plain old javascript if 
you have a reference to the native event object.

The recipes below are for Dojo 0.4.x; so even though they use 2.1.x 
tags, the javascript itself also works in Struts 2.0.x; you just have to 
write the javascript yourself thats included by within the new tag widgets.

http://struts.apache.org/2.x/docs/ajax-and-javascript-recipes.html

Pablo Vázquez Blázquez wrote:
> <script type="text/javascript">
>    var form = document.forms[0];
>    if ((form) &amp;&amp; (formIsDirty(form))) {
>        var a = confirm("There are unsaved changes. Do you want to 
> continue?");
>        if (!a) {
>            dojo.event.topic.publish("/cancelNavigation");
>           //HOW TO CANCEL NAVIGATION??
>        }
>    }
>      onbeforeunload = function(e) {
>        if (formIsDirty(document.forms[0])) {
>            e.returnValue = "There are unsaved changes.";
>        }
>    }
> </script>
>
> When calling topic "/cancelNavigation" the event paremeter is 
> undefined... Do you know any way to cancel navigation? I mean, cancel 
> rendering the served page.
>
>
> Jeromy Evans escribió:
>> Pablo Vázquez Blázquez wrote:
>>> Using dojo.addOnUnload(function) neither works. Besides that, I 
>>> would need sht like dojo.addOnBeforeUnload, but it does not exist.
>>>
>>> I don´t think I should subscribe for an ajax-request-completion 
>>> event, but for the beforeunload one, don´t I?
>>>
>>> Thanks.
>>
>> Use the dojo.connect function to listen to an arbitrary event.  See 
>> the comments to this related post: 
>> http://dojotoolkit.org/forum/dojo-core-dojo-0-9/dojo-core-support/when-does-unload-event-get-fired

>>
>>
>> I don't use it myself. Just pointing you in the right direction.
>>
>> Also, if the script is inline within your ajax response, see the 
>> recently updated notes on Handling AJAX Responses here:
>> http://struts.apache.org/2.x/docs/ajax-tags.html
>> (its written for 2.1 but mostly applies)
>> I'd consider turning on separateScritpts as well.
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message