You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam Gordon <Ad...@readytalk.com> on 2006/11/28 21:43:21 UTC

Struts, AJAX, JSP, and JavaScript question

I have a JSP and there's a link in the rendered page that makes an AJAX call
(to a Struts action) when clicked.  The results of that action, and the
contents of the response are set as the innerHTML on a hidden <div> defined
inside the afore mentioned rendered page.  The <div> is then un-hid.

Everything is working correctly except for one part:  When the div is
displayed, the JavaScript code in the contents returned by the AJAX call
isn't being executed and thus, the contents of the <div> aren't set up
correctly.

Does anyone know a way to have the JavaScript be executed?  Or force the
browser to execute it? 

I used to have an <iframe> and everything worked great, but there was a bad
side effect with session timeouts and so we've decided to not use them.

Any help would be appreciated.  Thanks.

-Adam


Re: Struts, AJAX, JSP, and JavaScript question

Posted by Adam Gordon <ad...@readytalk.com>.
Martin-

I could, but it's really nasty.  I've pasted the function where I use 
execScripts() below.  See my response to Frank prior to this response.  
Basically the JSP page we're requesting via the AJAX call is dynamically 
building an HTML table with options retrieved from the database and 
preloaded into a J/S array using JSTL tags.  After the array is loaded, 
we build the HTML table from the contents of the array.  The problem 
became apparent when the function to rebuild the table at page load time 
was not being executed and we ran into scoping problems with the J/S 
functions.  I wound up having to put them in the outer page and it made 
the two JSP's so tightly coupled that it made almost no sense to have 
separate JSPs...

Anyway, we've decided to leave the iframe in there for now as this page 
is going to be redone by our sub for version 2.0.

  function popCustomRegPanel(recordingId) {

    var url = "RecordingCustomRegistration.do?id=" + recordingId;

    loadXMLDoc(url,

      function() {

        if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {

          // this checks to make sure our session is still active and we 
have not
          // been logged out
          if (xmlhttp.getResponseHeader("validSession")) {

            // retrieve the response text (HTML) and evaluate the JavaScript
            // code so that the table is generated correctly.
            var customRegContentDiv =
              document.getElementById('customRegContent');

            customRegContentDiv.innerHTML = xmlhttp.responseText;
            execScripts(customRegContentDiv.innerHTML);

            show('customRegPanel');
            show('disable');
          }
          else {
            // reload the page and dump user at login page
            window.location.reload();
          }
        }
      });
  }

-adam

Martin Gainty wrote:
> Hi Adam-
>
> Could you post your JSP?
> in particular could we see XMLHttpRequest.OnReadyStateChange AND the javascript function which is the receptor for the Asynchronous call
>
> Thanks,
> M
> This e-mail communication and any attachments may contain confidential and privileged information for the use of the 
> designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
> this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its 
> contents
> ----- Original Message ----- 
> From: "Adam Gordon" <Ad...@readytalk.com>
> To: <us...@struts.apache.org>
> Sent: Tuesday, November 28, 2006 3:43 PM
> Subject: Struts, AJAX, JSP, and JavaScript question
>
>
>> I have a JSP and there's a link in the rendered page that makes an AJAX call
>> (to a Struts action) when clicked.  The results of that action, and the
>> contents of the response are set as the innerHTML on a hidden <div> defined
>> inside the afore mentioned rendered page.  The <div> is then un-hid.
>>
>> Everything is working correctly except for one part:  When the div is
>> displayed, the JavaScript code in the contents returned by the AJAX call
>> isn't being executed and thus, the contents of the <div> aren't set up
>> correctly.
>>
>> Does anyone know a way to have the JavaScript be executed?  Or force the
>> browser to execute it? 
>>
>> I used to have an <iframe> and everything worked great, but there was a bad
>> side effect with session timeouts and so we've decided to not use them.
>>
>> Any help would be appreciated.  Thanks.
>>
>> -Adam
>>
>>

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


Re: Struts, AJAX, JSP, and JavaScript question

Posted by Martin Gainty <mg...@hotmail.com>.
Hi Adam-

Could you post your JSP?
in particular could we see XMLHttpRequest.OnReadyStateChange AND the javascript function which is the receptor for the Asynchronous call

Thanks,
M
This e-mail communication and any attachments may contain confidential and privileged information for the use of the 
designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its 
contents
----- Original Message ----- 
From: "Adam Gordon" <Ad...@readytalk.com>
To: <us...@struts.apache.org>
Sent: Tuesday, November 28, 2006 3:43 PM
Subject: Struts, AJAX, JSP, and JavaScript question


>I have a JSP and there's a link in the rendered page that makes an AJAX call
> (to a Struts action) when clicked.  The results of that action, and the
> contents of the response are set as the innerHTML on a hidden <div> defined
> inside the afore mentioned rendered page.  The <div> is then un-hid.
> 
> Everything is working correctly except for one part:  When the div is
> displayed, the JavaScript code in the contents returned by the AJAX call
> isn't being executed and thus, the contents of the <div> aren't set up
> correctly.
> 
> Does anyone know a way to have the JavaScript be executed?  Or force the
> browser to execute it? 
> 
> I used to have an <iframe> and everything worked great, but there was a bad
> side effect with session timeouts and so we've decided to not use them.
> 
> Any help would be appreciated.  Thanks.
> 
> -Adam
> 
>

Re: Struts, AJAX, JSP, and JavaScript question

Posted by Adam Gordon <ad...@readytalk.com>.
Frank-

Yikes, I had no idea this thread would take on a life of its 
own...regardless, the execScripts function was exactly what I was 
looking for....had to tweak it to accomodate for the 
"type='text/javascript'" attribute on an opening <script> tag, but it works.

The situation has actually become rather complicated.  Before, we just 
has a JSP making an AJAX call and dumping the response in an iframe.  
The problem with that is that if the user's session expired and for 
whatever reason, the page didn't refresh as designed, then any action by 
the user in the iframe would cause the iframe to display our login 
page...not good...

So, the solution I was thinking of and have started implementing is to 
use a <div> instead by taking the results of the AJAX call and dump them 
in the <div> and display it.  This is slowly becoming a nightmare as I'm 
running into scoping issues w/ J/S functions not being seen by HTML 
widgets in the <div> contents etc.  Additionally, I had to construct an 
AJAX POST routine for submitting the contents of the <div> for saving 
which opens another can of worms w.r.t. encoding the parameters 
correctly, etc and correctly dealing with save failures and displaying 
them to the user.

I just spoke w/ our proj. mgr. we've decided to leave the iframe in 
because we're redoing the JSP page where this problem is situated for 
version 2.0 of our web app.

But thanks for the heads up - it did work.

-Adam

Frank W. Zammetti wrote:
> Hi Adam,
>
> If your doing straight AJAX yourself, i.e., directly interacting with the
> XMLHttpRequest object, this won't execute script for you automatically. 
> In fact, it won't do much of anything for you automatially, aside from
> parsing XML if that's your return type.  Otherwise, it's just text to the
> object and you'll have to execute scripts yourself.
>
> Another poster gave you some info if your using S2, but I'm guessing by
> your description your using S1.  In that case, continue reading! :)
>
> The AjaxParts Taglib (APT) in Java Web Parts (JWP) takes care of this for
> you... you can certainly switch over to using APT, but if you just want
> some code to execute scripts, take a look here:
>
> http://javawebparts.cvs.sourceforge.net/javawebparts/javawebparts/WEB-INF/src/javawebparts/ajaxparts/taglib/resources/AjaxPartsTaglib.js?view=markup
>
> Down around line 313 you'll find the execScripts() function... simply yank
> that out and use it on the responseText from XMLHttpRequest and you'll be
> good to go.
>
> If you are interested in looking at APT, here's a link:
>
> http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/taglib/package-summary.html
>
> And for JWP in general:
>
> http://javawebparts.sourceforge.net
>
> Hth,
> Frank
>
>
>   

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


Re: Struts, AJAX, JSP, and JavaScript question

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
On Wed, November 29, 2006 8:30 am, Martin Gainty wrote:
> I wholeheartedly agree that JavaScript and any '<pseudo>language' that
> ends with Script should be avoided at all costs!

Wait, don't put those words in my mouth :)  I said some people consider
eval() to be bad, not scripting languages... I have no problem with
scripting languages when used correctly (and I'm not as fanatical about
avoiding eval() as some people are). :)

Frank


>
> Thanks Frank,
>
> M-
> This e-mail communication and any attachments may contain confidential and
> privileged information for the use of the
> designated recipients named above. If you are not the intended recipient,
> you are hereby notified that you have received
> this communication in error and that any review, disclosure,
> dissemination, distribution or copying of it or its
> contents
> ----- Original Message -----
> From: "Frank W. Zammetti" <fz...@omnytex.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Wednesday, November 29, 2006 12:49 AM
> Subject: Re: Struts, AJAX, JSP, and JavaScript question
>
>
>> That will only work if the response is nothing but JavaScript, in which
>> case your 100% correct (although many people say that eval() should be
>> renamed evil() and should be avoided like the plague... I'm not *quite*
>> that extreme in my avoidance of it).
>>
>> As a quick proof:
>>
>> <html>
>>   <head>
>>       <script>
>>         var s = "";
>> //        s += "<" + "html" + ">";
>> //        s += "<" + "head" + ">";
>> //        s += "<" + "script" + ">";
>>         s += "alert('test');";
>> //        s += "<" + "/script" + ">";
>> //        s += "<" + "/head" + ">";
>> //        s += "<" + "body" + ">";
>> //        s += "Hello";
>> //        s += "<" + "/body" + ">";
>> //        s += "<" + "/html" + ">";
>>         function testit() {
>>           eval(s);
>>         }
>>       </script>
>>   </head>
>>   <body>
>>     The Body
>>     <input type="button" value="testit" onclick="testit();">
>>   </body>
>> </html>
>>
>> Load this file in your browser and you'll find that you get an alert, as
>> expected... now, uncomment the commented lines and reload and you'll see
>> that it no longer pops the alert (interestingly, in IE I get a syntax
>> error, because it's trying to interpret the markup as script, but in FF
>> it just quietly doesn't work, not even a notice in Firebug).
>>
>> So, if the idea is to execute script blocks that are part of an HTML
>> response, a simple eval() won't work... but if all your returning is
>> script, then I definitely echo Chris' suggestion and would go with
>> eval() (regardless of who wants to slap your hand with a ruler).
>>
>> Frank
>>
>>
>> Chris Pratt wrote:
>>> Or you could just call eval(ajax.responseText).
>>>  (*Chris*)
>>>
>>> On 11/28/06, Frank W. Zammetti <fz...@omnytex.com> wrote:
>>>>
>>>> Hi Adam,
>>>>
>>>> If your doing straight AJAX yourself, i.e., directly interacting with
>>>> the
>>>> XMLHttpRequest object, this won't execute script for you
>>>> automatically.
>>>> In fact, it won't do much of anything for you automatially, aside
>>>> from
>>>> parsing XML if that's your return type.  Otherwise, it's just text to
>>>> the
>>>> object and you'll have to execute scripts yourself.
>>>>
>>>> Another poster gave you some info if your using S2, but I'm guessing
>>>> by
>>>> your description your using S1.  In that case, continue reading! :)
>>>>
>>>> The AjaxParts Taglib (APT) in Java Web Parts (JWP) takes care of this
>>>> for
>>>> you... you can certainly switch over to using APT, but if you just
>>>> want
>>>> some code to execute scripts, take a look here:
>>>>
>>>>
>>>> http://javawebparts.cvs.sourceforge.net/javawebparts/javawebparts/WEB-INF/src/javawebparts/ajaxparts/taglib/resources/AjaxPartsTaglib.js?view=markup
>>>>
>>>>
>>>> Down around line 313 you'll find the execScripts() function... simply
>>>> yank
>>>> that out and use it on the responseText from XMLHttpRequest and you'll
>>>> be
>>>> good to go.
>>>>
>>>> If you are interested in looking at APT, here's a link:
>>>>
>>>>
>>>> http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/taglib/package-summary.html
>>>>
>>>>
>>>> And for JWP in general:
>>>>
>>>> http://javawebparts.sourceforge.net
>>>>
>>>> Hth,
>>>> Frank
>>>>
>>>>
>>>> --
>>>> Frank W. Zammetti
>>>> Founder and Chief Software Architect
>>>> Omnytex Technologies
>>>> http://www.omnytex.com
>>>> AIM/Yahoo: fzammetti
>>>> MSN: fzammetti@hotmail.com
>>>> Author of "Practical Ajax Projects With Java Technology"
>>>> (2006, Apress, ISBN 1-59059-695-1)
>>>> Java Web Parts - http://javawebparts.sourceforge.net
>>>> Supplying the wheel, so you don't have to reinvent it!
>>>>
>>>> On Tue, November 28, 2006 3:43 pm, Adam Gordon wrote:
>>>> > I have a JSP and there's a link in the rendered page that makes an
>>>> AJAX
>>>> > call
>>>> > (to a Struts action) when clicked.  The results of that action, and
>>>> the
>>>> > contents of the response are set as the innerHTML on a hidden <div>
>>>> > defined
>>>> > inside the afore mentioned rendered page.  The <div> is then
>>>> un-hid.
>>>> >
>>>> > Everything is working correctly except for one part:  When the div
>>>> is
>>>> > displayed, the JavaScript code in the contents returned by the AJAX
>>>> call
>>>> > isn't being executed and thus, the contents of the <div> aren't set
>>>> up
>>>> > correctly.
>>>> >
>>>> > Does anyone know a way to have the JavaScript be executed?  Or force
>>>> the
>>>> > browser to execute it?
>>>> >
>>>> > I used to have an <iframe> and everything worked great, but there
>>>> was a
>>>> > bad
>>>> > side effect with session timeouts and so we've decided to not use
>>>> them.
>>>> >
>>>> > Any help would be appreciated.  Thanks.
>>>> >
>>>> > -Adam
>>>> >
>>>> >
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>
>>
>> --
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>> AIM/Yahoo: fzammetti
>> MSN: fzammetti@hotmail.com
>> Author of "Practical Ajax Projects With Java Technology"
>>  (2006, Apress, ISBN 1-59059-695-1)
>> Java Web Parts - http://javawebparts.sourceforge.net
>>  Supplying the wheel, so you don't have to reinvent it!
>>
>> ---------------------------------------------------------------------
>> 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


Re: Struts, AJAX, JSP, and JavaScript question

Posted by Martin Gainty <mg...@hotmail.com>.
I haven't seen Ajax functionality embedded in Struts so I provided the solution as the classic 5 min q&d solution
I wholeheartedly agree that JavaScript and any '<pseudo>language' that ends with Script should be avoided at all costs!

Thanks Frank,

M-
This e-mail communication and any attachments may contain confidential and privileged information for the use of the 
designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received
this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its 
contents
----- Original Message ----- 
From: "Frank W. Zammetti" <fz...@omnytex.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Wednesday, November 29, 2006 12:49 AM
Subject: Re: Struts, AJAX, JSP, and JavaScript question


> That will only work if the response is nothing but JavaScript, in which 
> case your 100% correct (although many people say that eval() should be 
> renamed evil() and should be avoided like the plague... I'm not *quite* 
> that extreme in my avoidance of it).
> 
> As a quick proof:
> 
> <html>
>   <head>
>       <script>
>         var s = "";
> //        s += "<" + "html" + ">";
> //        s += "<" + "head" + ">";
> //        s += "<" + "script" + ">";
>         s += "alert('test');";
> //        s += "<" + "/script" + ">";
> //        s += "<" + "/head" + ">";
> //        s += "<" + "body" + ">";
> //        s += "Hello";
> //        s += "<" + "/body" + ">";
> //        s += "<" + "/html" + ">";
>         function testit() {
>           eval(s);
>         }
>       </script>
>   </head>
>   <body>
>     The Body
>     <input type="button" value="testit" onclick="testit();">
>   </body>
> </html>
> 
> Load this file in your browser and you'll find that you get an alert, as 
> expected... now, uncomment the commented lines and reload and you'll see 
> that it no longer pops the alert (interestingly, in IE I get a syntax 
> error, because it's trying to interpret the markup as script, but in FF 
> it just quietly doesn't work, not even a notice in Firebug).
> 
> So, if the idea is to execute script blocks that are part of an HTML 
> response, a simple eval() won't work... but if all your returning is 
> script, then I definitely echo Chris' suggestion and would go with 
> eval() (regardless of who wants to slap your hand with a ruler).
> 
> Frank
> 
> 
> Chris Pratt wrote:
>> Or you could just call eval(ajax.responseText).
>>  (*Chris*)
>> 
>> On 11/28/06, Frank W. Zammetti <fz...@omnytex.com> wrote:
>>>
>>> Hi Adam,
>>>
>>> If your doing straight AJAX yourself, i.e., directly interacting with the
>>> XMLHttpRequest object, this won't execute script for you automatically.
>>> In fact, it won't do much of anything for you automatially, aside from
>>> parsing XML if that's your return type.  Otherwise, it's just text to the
>>> object and you'll have to execute scripts yourself.
>>>
>>> Another poster gave you some info if your using S2, but I'm guessing by
>>> your description your using S1.  In that case, continue reading! :)
>>>
>>> The AjaxParts Taglib (APT) in Java Web Parts (JWP) takes care of this for
>>> you... you can certainly switch over to using APT, but if you just want
>>> some code to execute scripts, take a look here:
>>>
>>>
>>> http://javawebparts.cvs.sourceforge.net/javawebparts/javawebparts/WEB-INF/src/javawebparts/ajaxparts/taglib/resources/AjaxPartsTaglib.js?view=markup 
>>>
>>>
>>> Down around line 313 you'll find the execScripts() function... simply 
>>> yank
>>> that out and use it on the responseText from XMLHttpRequest and you'll be
>>> good to go.
>>>
>>> If you are interested in looking at APT, here's a link:
>>>
>>>
>>> http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/taglib/package-summary.html 
>>>
>>>
>>> And for JWP in general:
>>>
>>> http://javawebparts.sourceforge.net
>>>
>>> Hth,
>>> Frank
>>>
>>>
>>> -- 
>>> Frank W. Zammetti
>>> Founder and Chief Software Architect
>>> Omnytex Technologies
>>> http://www.omnytex.com
>>> AIM/Yahoo: fzammetti
>>> MSN: fzammetti@hotmail.com
>>> Author of "Practical Ajax Projects With Java Technology"
>>> (2006, Apress, ISBN 1-59059-695-1)
>>> Java Web Parts - http://javawebparts.sourceforge.net
>>> Supplying the wheel, so you don't have to reinvent it!
>>>
>>> On Tue, November 28, 2006 3:43 pm, Adam Gordon wrote:
>>> > I have a JSP and there's a link in the rendered page that makes an AJAX
>>> > call
>>> > (to a Struts action) when clicked.  The results of that action, and the
>>> > contents of the response are set as the innerHTML on a hidden <div>
>>> > defined
>>> > inside the afore mentioned rendered page.  The <div> is then un-hid.
>>> >
>>> > Everything is working correctly except for one part:  When the div is
>>> > displayed, the JavaScript code in the contents returned by the AJAX 
>>> call
>>> > isn't being executed and thus, the contents of the <div> aren't set up
>>> > correctly.
>>> >
>>> > Does anyone know a way to have the JavaScript be executed?  Or force 
>>> the
>>> > browser to execute it?
>>> >
>>> > I used to have an <iframe> and everything worked great, but there was a
>>> > bad
>>> > side effect with session timeouts and so we've decided to not use them.
>>> >
>>> > Any help would be appreciated.  Thanks.
>>> >
>>> > -Adam
>>> >
>>> >
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>> 
> 
> -- 
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> AIM/Yahoo: fzammetti
> MSN: fzammetti@hotmail.com
> Author of "Practical Ajax Projects With Java Technology"
>  (2006, Apress, ISBN 1-59059-695-1)
> Java Web Parts - http://javawebparts.sourceforge.net
>  Supplying the wheel, so you don't have to reinvent it!
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

Re: Struts, AJAX, JSP, and JavaScript question

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
That will only work if the response is nothing but JavaScript, in which 
case your 100% correct (although many people say that eval() should be 
renamed evil() and should be avoided like the plague... I'm not *quite* 
that extreme in my avoidance of it).

As a quick proof:

<html>
   <head>
       <script>
         var s = "";
//        s += "<" + "html" + ">";
//        s += "<" + "head" + ">";
//        s += "<" + "script" + ">";
         s += "alert('test');";
//        s += "<" + "/script" + ">";
//        s += "<" + "/head" + ">";
//        s += "<" + "body" + ">";
//        s += "Hello";
//        s += "<" + "/body" + ">";
//        s += "<" + "/html" + ">";
         function testit() {
           eval(s);
         }
       </script>
   </head>
   <body>
     The Body
     <input type="button" value="testit" onclick="testit();">
   </body>
</html>

Load this file in your browser and you'll find that you get an alert, as 
expected... now, uncomment the commented lines and reload and you'll see 
that it no longer pops the alert (interestingly, in IE I get a syntax 
error, because it's trying to interpret the markup as script, but in FF 
it just quietly doesn't work, not even a notice in Firebug).

So, if the idea is to execute script blocks that are part of an HTML 
response, a simple eval() won't work... but if all your returning is 
script, then I definitely echo Chris' suggestion and would go with 
eval() (regardless of who wants to slap your hand with a ruler).

Frank


Chris Pratt wrote:
> Or you could just call eval(ajax.responseText).
>  (*Chris*)
> 
> On 11/28/06, Frank W. Zammetti <fz...@omnytex.com> wrote:
>>
>> Hi Adam,
>>
>> If your doing straight AJAX yourself, i.e., directly interacting with the
>> XMLHttpRequest object, this won't execute script for you automatically.
>> In fact, it won't do much of anything for you automatially, aside from
>> parsing XML if that's your return type.  Otherwise, it's just text to the
>> object and you'll have to execute scripts yourself.
>>
>> Another poster gave you some info if your using S2, but I'm guessing by
>> your description your using S1.  In that case, continue reading! :)
>>
>> The AjaxParts Taglib (APT) in Java Web Parts (JWP) takes care of this for
>> you... you can certainly switch over to using APT, but if you just want
>> some code to execute scripts, take a look here:
>>
>>
>> http://javawebparts.cvs.sourceforge.net/javawebparts/javawebparts/WEB-INF/src/javawebparts/ajaxparts/taglib/resources/AjaxPartsTaglib.js?view=markup 
>>
>>
>> Down around line 313 you'll find the execScripts() function... simply 
>> yank
>> that out and use it on the responseText from XMLHttpRequest and you'll be
>> good to go.
>>
>> If you are interested in looking at APT, here's a link:
>>
>>
>> http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/taglib/package-summary.html 
>>
>>
>> And for JWP in general:
>>
>> http://javawebparts.sourceforge.net
>>
>> Hth,
>> Frank
>>
>>
>> -- 
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>> AIM/Yahoo: fzammetti
>> MSN: fzammetti@hotmail.com
>> Author of "Practical Ajax Projects With Java Technology"
>> (2006, Apress, ISBN 1-59059-695-1)
>> Java Web Parts - http://javawebparts.sourceforge.net
>> Supplying the wheel, so you don't have to reinvent it!
>>
>> On Tue, November 28, 2006 3:43 pm, Adam Gordon wrote:
>> > I have a JSP and there's a link in the rendered page that makes an AJAX
>> > call
>> > (to a Struts action) when clicked.  The results of that action, and the
>> > contents of the response are set as the innerHTML on a hidden <div>
>> > defined
>> > inside the afore mentioned rendered page.  The <div> is then un-hid.
>> >
>> > Everything is working correctly except for one part:  When the div is
>> > displayed, the JavaScript code in the contents returned by the AJAX 
>> call
>> > isn't being executed and thus, the contents of the <div> aren't set up
>> > correctly.
>> >
>> > Does anyone know a way to have the JavaScript be executed?  Or force 
>> the
>> > browser to execute it?
>> >
>> > I used to have an <iframe> and everything worked great, but there was a
>> > bad
>> > side effect with session timeouts and so we've decided to not use them.
>> >
>> > Any help would be appreciated.  Thanks.
>> >
>> > -Adam
>> >
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
  (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
  Supplying the wheel, so you don't have to reinvent it!

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


Re: Struts, AJAX, JSP, and JavaScript question

Posted by Chris Pratt <th...@gmail.com>.
Or you could just call eval(ajax.responseText).
  (*Chris*)

On 11/28/06, Frank W. Zammetti <fz...@omnytex.com> wrote:
>
> Hi Adam,
>
> If your doing straight AJAX yourself, i.e., directly interacting with the
> XMLHttpRequest object, this won't execute script for you automatically.
> In fact, it won't do much of anything for you automatially, aside from
> parsing XML if that's your return type.  Otherwise, it's just text to the
> object and you'll have to execute scripts yourself.
>
> Another poster gave you some info if your using S2, but I'm guessing by
> your description your using S1.  In that case, continue reading! :)
>
> The AjaxParts Taglib (APT) in Java Web Parts (JWP) takes care of this for
> you... you can certainly switch over to using APT, but if you just want
> some code to execute scripts, take a look here:
>
>
> http://javawebparts.cvs.sourceforge.net/javawebparts/javawebparts/WEB-INF/src/javawebparts/ajaxparts/taglib/resources/AjaxPartsTaglib.js?view=markup
>
> Down around line 313 you'll find the execScripts() function... simply yank
> that out and use it on the responseText from XMLHttpRequest and you'll be
> good to go.
>
> If you are interested in looking at APT, here's a link:
>
>
> http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/taglib/package-summary.html
>
> And for JWP in general:
>
> http://javawebparts.sourceforge.net
>
> Hth,
> Frank
>
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> AIM/Yahoo: fzammetti
> MSN: fzammetti@hotmail.com
> Author of "Practical Ajax Projects With Java Technology"
> (2006, Apress, ISBN 1-59059-695-1)
> Java Web Parts - http://javawebparts.sourceforge.net
> Supplying the wheel, so you don't have to reinvent it!
>
> On Tue, November 28, 2006 3:43 pm, Adam Gordon wrote:
> > I have a JSP and there's a link in the rendered page that makes an AJAX
> > call
> > (to a Struts action) when clicked.  The results of that action, and the
> > contents of the response are set as the innerHTML on a hidden <div>
> > defined
> > inside the afore mentioned rendered page.  The <div> is then un-hid.
> >
> > Everything is working correctly except for one part:  When the div is
> > displayed, the JavaScript code in the contents returned by the AJAX call
> > isn't being executed and thus, the contents of the <div> aren't set up
> > correctly.
> >
> > Does anyone know a way to have the JavaScript be executed?  Or force the
> > browser to execute it?
> >
> > I used to have an <iframe> and everything worked great, but there was a
> > bad
> > side effect with session timeouts and so we've decided to not use them.
> >
> > Any help would be appreciated.  Thanks.
> >
> > -Adam
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts, AJAX, JSP, and JavaScript question

Posted by Musachy Barroso <mb...@wfscorp.com>.
You will save a lot of time if you use something that is done already, 
and tested, like the links provided by Frank. If you still want to try 
it yourself you can check "Bind.js" :

http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/struts/widget/Bind.js?view=markup

musachy

Frank W. Zammetti wrote:
> Hi Adam,
>
> If your doing straight AJAX yourself, i.e., directly interacting with the
> XMLHttpRequest object, this won't execute script for you automatically. 
> In fact, it won't do much of anything for you automatially, aside from
> parsing XML if that's your return type.  Otherwise, it's just text to the
> object and you'll have to execute scripts yourself.
>
> Another poster gave you some info if your using S2, but I'm guessing by
> your description your using S1.  In that case, continue reading! :)
>
> The AjaxParts Taglib (APT) in Java Web Parts (JWP) takes care of this for
> you... you can certainly switch over to using APT, but if you just want
> some code to execute scripts, take a look here:
>
> http://javawebparts.cvs.sourceforge.net/javawebparts/javawebparts/WEB-INF/src/javawebparts/ajaxparts/taglib/resources/AjaxPartsTaglib.js?view=markup
>
> Down around line 313 you'll find the execScripts() function... simply yank
> that out and use it on the responseText from XMLHttpRequest and you'll be
> good to go.
>
> If you are interested in looking at APT, here's a link:
>
> http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/taglib/package-summary.html
>
> And for JWP in general:
>
> http://javawebparts.sourceforge.net
>
> Hth,
> Frank
>
>
>   


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


Re: Struts, AJAX, JSP, and JavaScript question

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Hi Adam,

If your doing straight AJAX yourself, i.e., directly interacting with the
XMLHttpRequest object, this won't execute script for you automatically. 
In fact, it won't do much of anything for you automatially, aside from
parsing XML if that's your return type.  Otherwise, it's just text to the
object and you'll have to execute scripts yourself.

Another poster gave you some info if your using S2, but I'm guessing by
your description your using S1.  In that case, continue reading! :)

The AjaxParts Taglib (APT) in Java Web Parts (JWP) takes care of this for
you... you can certainly switch over to using APT, but if you just want
some code to execute scripts, take a look here:

http://javawebparts.cvs.sourceforge.net/javawebparts/javawebparts/WEB-INF/src/javawebparts/ajaxparts/taglib/resources/AjaxPartsTaglib.js?view=markup

Down around line 313 you'll find the execScripts() function... simply yank
that out and use it on the responseText from XMLHttpRequest and you'll be
good to go.

If you are interested in looking at APT, here's a link:

http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/taglib/package-summary.html

And for JWP in general:

http://javawebparts.sourceforge.net

Hth,
Frank


-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
 (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
 Supplying the wheel, so you don't have to reinvent it!

On Tue, November 28, 2006 3:43 pm, Adam Gordon wrote:
> I have a JSP and there's a link in the rendered page that makes an AJAX
> call
> (to a Struts action) when clicked.  The results of that action, and the
> contents of the response are set as the innerHTML on a hidden <div>
> defined
> inside the afore mentioned rendered page.  The <div> is then un-hid.
>
> Everything is working correctly except for one part:  When the div is
> displayed, the JavaScript code in the contents returned by the AJAX call
> isn't being executed and thus, the contents of the <div> aren't set up
> correctly.
>
> Does anyone know a way to have the JavaScript be executed?  Or force the
> browser to execute it?
>
> I used to have an <iframe> and everything worked great, but there was a
> bad
> side effect with session timeouts and so we've decided to not use them.
>
> Any help would be appreciated.  Thanks.
>
> -Adam
>
>


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


Re: Struts, AJAX, JSP, and JavaScript question

Posted by Musachy Barroso <mb...@wfscorp.com>.
In struts 2 we already do that for you(link tag and button tag in the 
ajax theme), this is the code to extract the javascript sections(from Dojo):

parse : function(s) {
    this.log("Parsing: " + s);
    var match = [];
    var tmp = [];
    var scripts = [];
    while(match){
      match = s.match(/<script([^>]*)>([\s\S]*?)<\/script>/i);
      if(!match){ break; }
      if(match[1]){
        attr = match[1].match(/src=(['"]?)([^"']*)\1/i);
        if(attr){
          // remove a dojo.js or dojo.js.uncompressed.js from remoteScripts
          // we declare all files with dojo.js as bad, regardless of folder
          var tmp2 = attr[2].search(/.*(\bdojo\b(?:\.uncompressed)?\.js)$/);
          if(tmp2 > -1){
            this.log("Security note! inhibit:"+attr[2]+" from  beeing 
loaded again.");
          }
        }
      }
      if(match[2]){
        // strip out all djConfig variables from script tags nodeValue
        // this is ABSOLUTLY needed as reinitialize djConfig after dojo 
is initialised
        // makes a dissaster greater than Titanic, update remove 
writeIncludes() to
        var sc = match[2].replace(/(?:var 
)?\bdjConfig\b(?:[\s]*=[\s]*\{[^}]+\}|\.[\w]*[\s]*=[\s]*[^;\n]*)?;?|dojo\.hostenv\.writeIncludes\(\s*\);?/g, 
"");
        if(!sc){ continue; }

        // cut out all dojo.require (...) calls, if we have execute
        // scripts false widgets dont get there require calls
        // does suck out possible widgetpackage registration as well
        tmp = [];
        while(tmp){
          tmp = 
sc.match(/dojo\.(?:(?:require(?:After)?(?:If)?)|(?:widget\.(?:manager\.)?registerWidgetPackage)|(?:(?:hostenv\.)?setModulePrefix))\((['"]).*?\1\)\s*;?/);
          if(!tmp){ break;}
          sc = sc.replace(tmp[0], "");
        }
        scripts.push(sc);
      }
      s = s.replace(/<script[^>]*>[\s\S]*?<\/script>/i, "");
    }

    return {
      text: s,
      scripts: scripts
    };
  }


and to execute it:

        var parsed = this.parse(data);
         //eval scripts
         if(parsed.scripts && parsed.scripts.length > 0) {
           var scripts = "";
           for(var i = 0; i < parsed.scripts.length; i++){
             scripts += parsed.scripts[i];
           }
           (new Function('_container_', scripts+'; return this;'))(this);
         }

where 'data' is the html returned from the action.

have fun :)

musachy

Adam Gordon wrote:
> I have a JSP and there's a link in the rendered page that makes an AJAX call
> (to a Struts action) when clicked.  The results of that action, and the
> contents of the response are set as the innerHTML on a hidden <div> defined
> inside the afore mentioned rendered page.  The <div> is then un-hid.
>
> Everything is working correctly except for one part:  When the div is
> displayed, the JavaScript code in the contents returned by the AJAX call
> isn't being executed and thus, the contents of the <div> aren't set up
> correctly.
>
> Does anyone know a way to have the JavaScript be executed?  Or force the
> browser to execute it? 
>
> I used to have an <iframe> and everything worked great, but there was a bad
> side effect with session timeouts and so we've decided to not use them.
>
> Any help would be appreciated.  Thanks.
>
> -Adam
>
>
>   


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