struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lbastil <>
Subject Re: [S2] why is javascript executed before DOM is updated
Date Tue, 21 Oct 2008 13:19:28 GMT

For me it is still not clear:

with struts 2.0.11, how can I:
modyfy DOM which is given back from an AJAX request with javascript at all?

suppose, I have a form, which is updated by a dojo ajax requst.
After the form is updated I wnat to execute a javascript which disables two
of the 
submit buttons in the form. Hoy can I do this task?

thank you in advance.

Jeromy Evans - Blue Sky Minds wrote:
> I think it is WW-1951.
> It's generally a bad idea to include inline scripts in a result loaded 
> via XHR because it varies from browser-to-browser and library-to-library 
> as to when the scripts are executed.  In this case, Dojo has the 
> responsibility to parse your result, extract the scripts and then 
> execute them (when separateScripts is false and executeScripts is 
> true).  If, for example, you only used element.innerHTML directly to 
> update your page the script would not be executed at all (in most 
> browsers).  The point is, the Dojo widget is explicitly separating and 
> executing your scripts in the result.
> In 2.1, revision #543927, the Bind widget was modified to execute 
> scripts after setting the content.  In 2.0, scripts are executed after 
> parsing but before setting the content.
> I think you have a couple of options:
>    - (recommended) refactor your javascript so its not inline.  For 
> example, you may be able to listen for an event instead
>    - if you're sure it's only s:submit that has the problem and s:div is 
> okay, have the submit publish a topic and have a s:div subscribe and 
> perform the request itself
>    - patch the widget in struts 2.0 with the same change as in 2.1, and 
> build your own dojo release.
> Hope that helps a little,
> Jeromy Evans
> lbastil wrote:
>> Is this the WW-1951 - issue?
>> And if so, is there any workaround for 2.0.11 release?
>> Thank you,
>> basti
>> lbastil wrote:
>>> I have a serious problem with an ajax submit.
>>> the scenario is the following:
>>> I submit a form with ajax submit button and I want to update the parent
>>> div (targets="...")
>>> The original content of this div and the result content contains a
>>> <script> section with
>>> javascript at the very end.
>>> Now the following happens: after pressing the submit button the ajax
>>> call
>>> is done correctly.
>>> But after that at first the script is executed, then the DOM is updated
>>> by
>>> replacing originally div 
>>> content with the result from ajax call.
>>> But this is not what I would expect. The javascript for instance changes
>>> some things (like
>>> enabling / disabling form elements), which are then overwritten by the
>>> DOM
>>> updating.
>>> The interesting thing is: originally the content of the div is also
>>> loaded
>>> / filled by ajax mechanisms,
>>> but not triggered from <s:submit>. In this first case the javascript is
>>> executed on the exact
>>> order, where it is placed in the code. Why not when doing it via
>>> <s:submit>?
>>> Can anybody explain me what is going on here and suggest a workaround?
>>> Thank you very much in advance,
>>> basti
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

View this message in context:
Sent from the Struts - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message