Struts2 + Dojo 0.4 + unbeforeunload problem

2008-09-05 Thread Pablo Vázquez Blázquez

Hi!!

If I have the following code in a jspx loaded via , when I go to 
another page (also loaded via ) the "onbeforeunload" event is not 
triggered. It is only triggered when the page is not loaded using ajax.


What can I do to make it works both when the page is downloaded at all 
from server and when only a part is using ajax (using  tag)?


http://www.w3.org/1999/xhtml";
   xmlns:jsp="http://java.sun.com/JSP/Page";
   xmlns:fmt="http://java.sun.com/jsp/jstl/fmt";
   xmlns:c="http://java.sun.com/jsp/jstl/core";
   xmlns:s="/struts-tags"
   xmlns:scheduler="/scheduler-html.tld"
   version="2.0">


   onbeforeunload = function() {
   if (formIsDirty(document.forms[1])) {
   return confirm('Unsaved changes. Do you want to continue?');
   }
   }
   


...


  



Thanks.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts2 + Dojo 0.4 + unbeforeunload problem

2008-09-11 Thread Pablo Vázquez Blázquez

No idea or miss-explanation?

Thanks.

Pablo Vázquez Blázquez escribió:

Hi!!

If I have the following code in a jspx loaded via , when I go 
to another page (also loaded via ) the "onbeforeunload" event 
is not triggered. It is only triggered when the page is not loaded 
using ajax.


What can I do to make it works both when the page is downloaded at all 
from server and when only a part is using ajax (using  tag)?


http://www.w3.org/1999/xhtml";
   xmlns:jsp="http://java.sun.com/JSP/Page";
   xmlns:fmt="http://java.sun.com/jsp/jstl/fmt";
   xmlns:c="http://java.sun.com/jsp/jstl/core";
   xmlns:s="/struts-tags"
   xmlns:scheduler="/scheduler-html.tld"
   version="2.0">


   onbeforeunload = function() {
   if (formIsDirty(document.forms[1])) {
return confirm('Unsaved changes. Do you want to continue?');
   }
   }
   


...


  

Thanks.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts2 + Dojo 0.4 + unbeforeunload problem

2008-09-11 Thread Jeromy Evans

Pablo Vázquez Blázquez wrote:

No idea or miss-explanation?



Use dojo's event model. You need to register a listener/subscriber for 
the event via dojo.


If you assign a listener directly to onbeforeunload or onload you'll 
overwrite the listeners that dojo needs to assign (or vice-versa, dojo 
will overwrite yours).


Check the dojo docs for examples. I can't think of it off the top of my 
head.


Also, there should be a dojo-specific event you can subscribe to for the 
completion of an ajax request, rather than the page-related events.  
Check the recipes for that.



Hope that helps a little.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts2 + Dojo 0.4 + unbeforeunload problem

2008-09-11 Thread Pablo Vázquez Blázquez
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.

Jeromy Evans escribió:

Pablo Vázquez Blázquez wrote:

No idea or miss-explanation?



Use dojo's event model. You need to register a listener/subscriber for 
the event via dojo.


If you assign a listener directly to onbeforeunload or onload you'll 
overwrite the listeners that dojo needs to assign (or vice-versa, dojo 
will overwrite yours).


Check the dojo docs for examples. I can't think of it off the top of 
my head.


Also, there should be a dojo-specific event you can subscribe to for 
the completion of an ajax request, rather than the page-related 
events.  Check the recipes for that.



Hope that helps a little.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts2 + Dojo 0.4 + unbeforeunload problem

2008-09-11 Thread Owen Berry
Javascript within a remote div is not evaluated by default. Not sure
about s:div, but sx:div has executeScripts which must be set to true.

Owen

On Fri, Sep 5, 2008 at 6:01 AM, Pablo Vázquez Blázquez
<[EMAIL PROTECTED]> wrote:
> Hi!!
>
> If I have the following code in a jspx loaded via , when I go to
> another page (also loaded via ) the "onbeforeunload" event is not
> triggered. It is only triggered when the page is not loaded using ajax.
>
> What can I do to make it works both when the page is downloaded at all from
> server and when only a part is using ajax (using  tag)?
>
> http://www.w3.org/1999/xhtml";
>   xmlns:jsp="http://java.sun.com/JSP/Page";
>   xmlns:fmt="http://java.sun.com/jsp/jstl/fmt";
>   xmlns:c="http://java.sun.com/jsp/jstl/core";
>   xmlns:s="/struts-tags"
>   xmlns:scheduler="/scheduler-html.tld"
>   version="2.0">
>
> 
>   onbeforeunload = function() {
>   if (formIsDirty(document.forms[1])) {
>   return confirm('Unsaved changes. Do you want to continue?');
>   }
>   }
>   
>
>action="UpdateTagDataSource" method="POST">
> ...
> 
>
>  
>
> Thanks.
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts2 + Dojo 0.4 + unbeforeunload problem

2008-09-11 Thread Pablo Vázquez Blázquez

I have executeScripts="true" in my  tag.

Thanks.

Owen Berry escribió:

Javascript within a remote div is not evaluated by default. Not sure
about s:div, but sx:div has executeScripts which must be set to true.

Owen

On Fri, Sep 5, 2008 at 6:01 AM, Pablo Vázquez Blázquez
<[EMAIL PROTECTED]> wrote:
  

Hi!!

If I have the following code in a jspx loaded via , when I go to
another page (also loaded via ) the "onbeforeunload" event is not
triggered. It is only triggered when the page is not loaded using ajax.

What can I do to make it works both when the page is downloaded at all from
server and when only a part is using ajax (using  tag)?

http://www.w3.org/1999/xhtml";
  xmlns:jsp="http://java.sun.com/JSP/Page";
  xmlns:fmt="http://java.sun.com/jsp/jstl/fmt";
  xmlns:c="http://java.sun.com/jsp/jstl/core";
  xmlns:s="/struts-tags"
  xmlns:scheduler="/scheduler-html.tld"
  version="2.0">


  onbeforeunload = function() {
  if (formIsDirty(document.forms[1])) {
  return confirm('Unsaved changes. Do you want to continue?');
  }
  }
  


...


 

Thanks.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



  


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts2 + Dojo 0.4 + unbeforeunload problem

2008-09-11 Thread Jeromy Evans

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts2 + Dojo 0.4 + unbeforeunload problem

2008-09-12 Thread Pablo Vázquez Blázquez

dojo.connect does not exist in dojo 0.4 :(

And separateScritpts attribute neither does in struts 2.0.9.

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts2 + Dojo 0.4 + unbeforeunload problem

2008-09-12 Thread Pablo Vázquez Blázquez


   var form = document.forms[0];
   if ((form) && (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.";
   }
   }


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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts2 + Dojo 0.4 + unbeforeunload problem

2008-09-12 Thread Jeromy Evans
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:


   var form = document.forms[0];
   if ((form) && (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.";
   }
   }


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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]