You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jim Collings <jl...@gmail.com> on 2009/12/17 11:11:50 UTC

JavaScript / AJAX + Struts 2?

So I have two actions and one jsp.  The idea is that one is for the
entire page and another is for putting into a <div> via a JavaScript
method.

Question:  How do I get items off of the value stack for use in JavaScript?


Jim C.

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


Re: JavaScript / AJAX + Struts 2?

Posted by Brian Thompson <el...@gmail.com>.
On Fri, Dec 18, 2009 at 6:37 AM, Jim Collings <jl...@gmail.com> wrote:

> Here is the answer that I was provided & used:
>
> 1. You can use the ${somethingFromTheValueStack} notation like so:
>
> onclick="onjavaScriptMethod('${value}');"
>
> I tried this but missed the ' marks because it's been so long since I
> did any JavaScript. I haven't tried this trick in an actual embedded
> script or script file. Just jsp's. Would be nice if it worked.  Does
> anyone know if it does?
>
>


It'll work fine in <script> tags embedded in your jsp, but it won't work in
external script files.

-Brian

Re: JavaScript / AJAX + Struts 2?

Posted by Jim Collings <jl...@gmail.com>.
Here is the answer that I was provided & used:

1. You can use the ${somethingFromTheValueStack} notation like so:

onclick="onjavaScriptMethod('${value}');"

I tried this but missed the ' marks because it's been so long since I
did any JavaScript. I haven't tried this trick in an actual embedded
script or script file. Just jsp's. Would be nice if it worked.  Does
anyone know if it does?


2. If you map the action to a jsp fragment, it can be placed in a div like so:

//First you need to get the request & handle some platform crap.
var request = false;
try {
 request = new XMLHttpRequest();
} catch (trymicrosoft) {
 try {
   request = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (othermicrosoft) {
   try {
     request = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (failed) {
     request = false;
   }
 }
}

if (!request)
 alert("Error initializing XMLHttpRequest!");

//***************************************************************
//Functions.
//***************************************************************
//Execute the action
function checkSomething(string) {
 var url = string + "/context/DoSomething.action";
 request.open("GET", url, true);
 request.onreadystatechange = updatePage();
 request.send(null);
}

//Update the page.
//Put the results in the div & display.
//Note there are two div tags. One is for results and the other for
processing messages like "Loading...".
function updatePage() {
 var d = document.getElementById("divResults");
 d.innerHTML = 'Loading...';
 var d1 = document.getElementById("divProcessing");
 d1.style.display="block";
 if (request.readyState == 4)
   d.innerHTML = request.responseText ;
   d1.style.display="none";
}


On Thu, Dec 17, 2009 at 5:11 AM, Jim Collings <jl...@gmail.com> wrote:
> So I have two actions and one jsp.  The idea is that one is for the
> entire page and another is for putting into a <div> via a JavaScript
> method.
>
> Question:  How do I get items off of the value stack for use in JavaScript?
>
>
> Jim C.
>

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


Re: JavaScript / AJAX + Struts 2?

Posted by john feng <jo...@gmail.com>.
You can use the action to get data from server to display in the <div> thru JS.
e.g., in your jsp, user selects a dropdown element of country name,
then it will get the state/province names data to be displayed in the
<div>. You can invoke an action for the dropdown value-change event to
get the data back (such as return null in the action) , then you can
use ajax object api to catch the data for JS to display into <div>.
This is hand coding it. If you use an ajax enabled tag framework, you
don't need to code to this details -of course you may have to set
properties instead.

John Feng

On Thu, Dec 17, 2009 at 5:11 AM, Jim Collings <jl...@gmail.com> wrote:
> So I have two actions and one jsp.  The idea is that one is for the
> entire page and another is for putting into a <div> via a JavaScript
> method.
>
> Question:  How do I get items off of the value stack for use in JavaScript?
>
>
> Jim C.
>
> ---------------------------------------------------------------------
> 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: JavaScript / AJAX + Struts 2?

Posted by Brian Thompson <el...@gmail.com>.
Thanks :)

Oh, and to the OP ... my (somewhat sloppy) pseudocode is only one way to do
it.  You could also set up Ajax calls to get data in JSON format from the
server.  It's simpler to start out by writing javascript values for whatever
you need from the value stack, though.

-Brian


On Thu, Dec 17, 2009 at 10:05 PM, dusty <du...@yahoo.com> wrote:

>
> I like how code is declared #fail because there probably is not a toString
> method.   lawl.  Please do not be distracted....Brian's code was a
> perfectly
> good example.
>
>
>
> Brian Thompson-5 wrote:
> >
> > In context of the other two examples, you're right; I should have used
> > something like
> >
> > var foo = <s:property value="%{foo.foobar}"/>; //int, boolean, etc.
> >
> > instead to be more clear.  The lack of quotes was deliberate, though ...
> > you
> > wouldn't want to quote a numeric value when you're setting it up that
> way.
> >
> > -Brian
> >
> >
> >
> > 2009/12/17 Paweł Wielgus <po...@gmail.com>
> >
> >> Hi Brian,
> >> i din't notice that it is a continuation of comment, so You are wright.
> >> As for first assignement, there are no ' or " chars around scriptlet
> >> so it will not work because most probably there is no variable named
> >> as the foo's toString value.
> >> Second and third assignement has them an will work.
> >>
> >> Best greetings,
> >> Pawel Wielgus.
> >>
> >> 2009/12/17, Brian Thompson <el...@gmail.com>:
> >> > TBH, I just wrote it as a quick "off the top of my head" example.  The
> >> basic
> >> > structure is sound, though -- I did that sort of thing all the time in
> >> my
> >> > struts project earlier this year.  What do you think is wrong with it?
> >> >
> >> > n.b. "foo.getBat()" does not belong on its own line - it's part of the
> >> > "//string retrieved..." comment.
> >> >
> >> > -Brian
> >> >
> >> >
> >> >
> >> > 2009/12/17 Paweł Wielgus <po...@gmail.com>
> >> >
> >> >> Hi Brian,
> >> >> have You tried running this code?
> >> >> i have a doubt about:
> >> >> foo.getBat() line.
> >> >> As far as i know it will not work.
> >> >>
> >> >> Also line:
> >> >> var foo = <s:property value="%{foo}"/>; //int, boolean, etc.
> >> >> will not work too.
> >> >>
> >> >> Best greetings,
> >> >> Paweł Wielgus.
> >> >>
> >> >>
> >> >> 2009/12/17 Brian Thompson <el...@gmail.com>:
> >> >> > Bwuh?  Just because your fridge doesn't have a built-in toaster,
> >> it's
> >> >> > worthless?
> >> >> >
> >> >> > Struts is helpful for stuff you'd want to do on the server side.
> >> >> >
> >> >> > An easy way to make stuff from the value stack available in
> >> javascript
> >> >> > is
> >> >> to
> >> >> > do this in the jsp:
> >> >> >
> >> >> > <script type="text/javascript">
> >> >> >
> >> >> > var foo = <s:property value="%{foo}"/>; //int, boolean, etc.
> >> >> > var bar = '<s:property value="%{bar}"/>';  //string
> >> >> > var bat = '<s:property value="%{foo.bat}"/>';  //string retrieved
> by
> >> >> > foo.getBat()
> >> >> >
> >> >> > //javascript logic goes here
> >> >> >
> >> >> > </script>
> >> >> >
> >> >> > Hope that helps,
> >> >> >
> >> >> > -Brian
> >> >> >
> >> >> > On Thu, Dec 17, 2009 at 8:33 AM, Jim Collings <jlistnews@gmail.com
> >
> >> >> wrote:
> >> >> >
> >> >> >> So it's impossible?  JavaScript and Struts 2 don't interact at
> all?
> >> >> >> What good is Struts 2 then?
> >> >> >>
> >> >> >> 2009/12/17 Paweł Wielgus <po...@gmail.com>:
> >> >> >> > Hi Jim,
> >> >> >> > action is on server side and javascript is on browser side,
> >> >> >> > they don't interact, You can generate js server side but that's
> >> it.
> >> >> >> > Js will be run in browser so it has no access to stack or action
> >> >> >> variables.
> >> >> >> >
> >> >> >> > Best greetings,
> >> >> >> > Paweł Wielgus.
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> > 2009/12/17 Jim Collings <jl...@gmail.com>:
> >> >> >> >> So I have two actions and one jsp.  The idea is that one is for
> >> the
> >> >> >> >> entire page and another is for putting into a <div> via a
> >> JavaScript
> >> >> >> >> method.
> >> >> >> >>
> >> >> >> >> Question:  How do I get items off of the value stack for use in
> >> >> >> JavaScript?
> >> >> >> >>
> >> >> >> >>
> >> >> >> >> Jim C.
> >> >> >> >>
> >> >> >> >>
> >> ---------------------------------------------------------------------
> >> >> >> >> 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
> >> >> >>
> >> >> >>
> >> >> >
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> 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
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/JavaScript---AJAX-%2B-Struts-2--tp26825831p26838826.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: JavaScript / AJAX + Struts 2?

Posted by dusty <du...@yahoo.com>.
I like how code is declared #fail because there probably is not a toString
method.   lawl.  Please do not be distracted....Brian's code was a perfectly
good example.



Brian Thompson-5 wrote:
> 
> In context of the other two examples, you're right; I should have used
> something like
> 
> var foo = <s:property value="%{foo.foobar}"/>; //int, boolean, etc.
> 
> instead to be more clear.  The lack of quotes was deliberate, though ...
> you
> wouldn't want to quote a numeric value when you're setting it up that way.
> 
> -Brian
> 
> 
> 
> 2009/12/17 Paweł Wielgus <po...@gmail.com>
> 
>> Hi Brian,
>> i din't notice that it is a continuation of comment, so You are wright.
>> As for first assignement, there are no ' or " chars around scriptlet
>> so it will not work because most probably there is no variable named
>> as the foo's toString value.
>> Second and third assignement has them an will work.
>>
>> Best greetings,
>> Pawel Wielgus.
>>
>> 2009/12/17, Brian Thompson <el...@gmail.com>:
>> > TBH, I just wrote it as a quick "off the top of my head" example.  The
>> basic
>> > structure is sound, though -- I did that sort of thing all the time in
>> my
>> > struts project earlier this year.  What do you think is wrong with it?
>> >
>> > n.b. "foo.getBat()" does not belong on its own line - it's part of the
>> > "//string retrieved..." comment.
>> >
>> > -Brian
>> >
>> >
>> >
>> > 2009/12/17 Paweł Wielgus <po...@gmail.com>
>> >
>> >> Hi Brian,
>> >> have You tried running this code?
>> >> i have a doubt about:
>> >> foo.getBat() line.
>> >> As far as i know it will not work.
>> >>
>> >> Also line:
>> >> var foo = <s:property value="%{foo}"/>; //int, boolean, etc.
>> >> will not work too.
>> >>
>> >> Best greetings,
>> >> Paweł Wielgus.
>> >>
>> >>
>> >> 2009/12/17 Brian Thompson <el...@gmail.com>:
>> >> > Bwuh?  Just because your fridge doesn't have a built-in toaster,
>> it's
>> >> > worthless?
>> >> >
>> >> > Struts is helpful for stuff you'd want to do on the server side.
>> >> >
>> >> > An easy way to make stuff from the value stack available in
>> javascript
>> >> > is
>> >> to
>> >> > do this in the jsp:
>> >> >
>> >> > <script type="text/javascript">
>> >> >
>> >> > var foo = <s:property value="%{foo}"/>; //int, boolean, etc.
>> >> > var bar = '<s:property value="%{bar}"/>';  //string
>> >> > var bat = '<s:property value="%{foo.bat}"/>';  //string retrieved by
>> >> > foo.getBat()
>> >> >
>> >> > //javascript logic goes here
>> >> >
>> >> > </script>
>> >> >
>> >> > Hope that helps,
>> >> >
>> >> > -Brian
>> >> >
>> >> > On Thu, Dec 17, 2009 at 8:33 AM, Jim Collings <jl...@gmail.com>
>> >> wrote:
>> >> >
>> >> >> So it's impossible?  JavaScript and Struts 2 don't interact at all?
>> >> >> What good is Struts 2 then?
>> >> >>
>> >> >> 2009/12/17 Paweł Wielgus <po...@gmail.com>:
>> >> >> > Hi Jim,
>> >> >> > action is on server side and javascript is on browser side,
>> >> >> > they don't interact, You can generate js server side but that's
>> it.
>> >> >> > Js will be run in browser so it has no access to stack or action
>> >> >> variables.
>> >> >> >
>> >> >> > Best greetings,
>> >> >> > Paweł Wielgus.
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > 2009/12/17 Jim Collings <jl...@gmail.com>:
>> >> >> >> So I have two actions and one jsp.  The idea is that one is for
>> the
>> >> >> >> entire page and another is for putting into a <div> via a
>> JavaScript
>> >> >> >> method.
>> >> >> >>
>> >> >> >> Question:  How do I get items off of the value stack for use in
>> >> >> JavaScript?
>> >> >> >>
>> >> >> >>
>> >> >> >> Jim C.
>> >> >> >>
>> >> >> >>
>> ---------------------------------------------------------------------
>> >> >> >> 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
>> >> >>
>> >> >>
>> >> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> 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
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/JavaScript---AJAX-%2B-Struts-2--tp26825831p26838826.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: JavaScript / AJAX + Struts 2?

Posted by Brian Thompson <el...@gmail.com>.
In context of the other two examples, you're right; I should have used
something like

var foo = <s:property value="%{foo.foobar}"/>; //int, boolean, etc.

instead to be more clear.  The lack of quotes was deliberate, though ... you
wouldn't want to quote a numeric value when you're setting it up that way.

-Brian



2009/12/17 Paweł Wielgus <po...@gmail.com>

> Hi Brian,
> i din't notice that it is a continuation of comment, so You are wright.
> As for first assignement, there are no ' or " chars around scriptlet
> so it will not work because most probably there is no variable named
> as the foo's toString value.
> Second and third assignement has them an will work.
>
> Best greetings,
> Pawel Wielgus.
>
> 2009/12/17, Brian Thompson <el...@gmail.com>:
> > TBH, I just wrote it as a quick "off the top of my head" example.  The
> basic
> > structure is sound, though -- I did that sort of thing all the time in my
> > struts project earlier this year.  What do you think is wrong with it?
> >
> > n.b. "foo.getBat()" does not belong on its own line - it's part of the
> > "//string retrieved..." comment.
> >
> > -Brian
> >
> >
> >
> > 2009/12/17 Paweł Wielgus <po...@gmail.com>
> >
> >> Hi Brian,
> >> have You tried running this code?
> >> i have a doubt about:
> >> foo.getBat() line.
> >> As far as i know it will not work.
> >>
> >> Also line:
> >> var foo = <s:property value="%{foo}"/>; //int, boolean, etc.
> >> will not work too.
> >>
> >> Best greetings,
> >> Paweł Wielgus.
> >>
> >>
> >> 2009/12/17 Brian Thompson <el...@gmail.com>:
> >> > Bwuh?  Just because your fridge doesn't have a built-in toaster, it's
> >> > worthless?
> >> >
> >> > Struts is helpful for stuff you'd want to do on the server side.
> >> >
> >> > An easy way to make stuff from the value stack available in javascript
> >> > is
> >> to
> >> > do this in the jsp:
> >> >
> >> > <script type="text/javascript">
> >> >
> >> > var foo = <s:property value="%{foo}"/>; //int, boolean, etc.
> >> > var bar = '<s:property value="%{bar}"/>';  //string
> >> > var bat = '<s:property value="%{foo.bat}"/>';  //string retrieved by
> >> > foo.getBat()
> >> >
> >> > //javascript logic goes here
> >> >
> >> > </script>
> >> >
> >> > Hope that helps,
> >> >
> >> > -Brian
> >> >
> >> > On Thu, Dec 17, 2009 at 8:33 AM, Jim Collings <jl...@gmail.com>
> >> wrote:
> >> >
> >> >> So it's impossible?  JavaScript and Struts 2 don't interact at all?
> >> >> What good is Struts 2 then?
> >> >>
> >> >> 2009/12/17 Paweł Wielgus <po...@gmail.com>:
> >> >> > Hi Jim,
> >> >> > action is on server side and javascript is on browser side,
> >> >> > they don't interact, You can generate js server side but that's it.
> >> >> > Js will be run in browser so it has no access to stack or action
> >> >> variables.
> >> >> >
> >> >> > Best greetings,
> >> >> > Paweł Wielgus.
> >> >> >
> >> >> >
> >> >> >
> >> >> > 2009/12/17 Jim Collings <jl...@gmail.com>:
> >> >> >> So I have two actions and one jsp.  The idea is that one is for
> the
> >> >> >> entire page and another is for putting into a <div> via a
> JavaScript
> >> >> >> method.
> >> >> >>
> >> >> >> Question:  How do I get items off of the value stack for use in
> >> >> JavaScript?
> >> >> >>
> >> >> >>
> >> >> >> Jim C.
> >> >> >>
> >> >> >>
> ---------------------------------------------------------------------
> >> >> >> 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
> >> >>
> >> >>
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> 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: JavaScript / AJAX + Struts 2?

Posted by Paweł Wielgus <po...@gmail.com>.
Hi Brian,
i din't notice that it is a continuation of comment, so You are wright.
As for first assignement, there are no ' or " chars around scriptlet
so it will not work because most probably there is no variable named
as the foo's toString value.
Second and third assignement has them an will work.

Best greetings,
Pawel Wielgus.

2009/12/17, Brian Thompson <el...@gmail.com>:
> TBH, I just wrote it as a quick "off the top of my head" example.  The basic
> structure is sound, though -- I did that sort of thing all the time in my
> struts project earlier this year.  What do you think is wrong with it?
>
> n.b. "foo.getBat()" does not belong on its own line - it's part of the
> "//string retrieved..." comment.
>
> -Brian
>
>
>
> 2009/12/17 Paweł Wielgus <po...@gmail.com>
>
>> Hi Brian,
>> have You tried running this code?
>> i have a doubt about:
>> foo.getBat() line.
>> As far as i know it will not work.
>>
>> Also line:
>> var foo = <s:property value="%{foo}"/>; //int, boolean, etc.
>> will not work too.
>>
>> Best greetings,
>> Paweł Wielgus.
>>
>>
>> 2009/12/17 Brian Thompson <el...@gmail.com>:
>> > Bwuh?  Just because your fridge doesn't have a built-in toaster, it's
>> > worthless?
>> >
>> > Struts is helpful for stuff you'd want to do on the server side.
>> >
>> > An easy way to make stuff from the value stack available in javascript
>> > is
>> to
>> > do this in the jsp:
>> >
>> > <script type="text/javascript">
>> >
>> > var foo = <s:property value="%{foo}"/>; //int, boolean, etc.
>> > var bar = '<s:property value="%{bar}"/>';  //string
>> > var bat = '<s:property value="%{foo.bat}"/>';  //string retrieved by
>> > foo.getBat()
>> >
>> > //javascript logic goes here
>> >
>> > </script>
>> >
>> > Hope that helps,
>> >
>> > -Brian
>> >
>> > On Thu, Dec 17, 2009 at 8:33 AM, Jim Collings <jl...@gmail.com>
>> wrote:
>> >
>> >> So it's impossible?  JavaScript and Struts 2 don't interact at all?
>> >> What good is Struts 2 then?
>> >>
>> >> 2009/12/17 Paweł Wielgus <po...@gmail.com>:
>> >> > Hi Jim,
>> >> > action is on server side and javascript is on browser side,
>> >> > they don't interact, You can generate js server side but that's it.
>> >> > Js will be run in browser so it has no access to stack or action
>> >> variables.
>> >> >
>> >> > Best greetings,
>> >> > Paweł Wielgus.
>> >> >
>> >> >
>> >> >
>> >> > 2009/12/17 Jim Collings <jl...@gmail.com>:
>> >> >> So I have two actions and one jsp.  The idea is that one is for the
>> >> >> entire page and another is for putting into a <div> via a JavaScript
>> >> >> method.
>> >> >>
>> >> >> Question:  How do I get items off of the value stack for use in
>> >> JavaScript?
>> >> >>
>> >> >>
>> >> >> Jim C.
>> >> >>
>> >> >> ---------------------------------------------------------------------
>> >> >> 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
>> >>
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> 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: JavaScript / AJAX + Struts 2?

Posted by Brian Thompson <el...@gmail.com>.
TBH, I just wrote it as a quick "off the top of my head" example.  The basic
structure is sound, though -- I did that sort of thing all the time in my
struts project earlier this year.  What do you think is wrong with it?

n.b. "foo.getBat()" does not belong on its own line - it's part of the
"//string retrieved..." comment.

-Brian



2009/12/17 Paweł Wielgus <po...@gmail.com>

> Hi Brian,
> have You tried running this code?
> i have a doubt about:
> foo.getBat() line.
> As far as i know it will not work.
>
> Also line:
> var foo = <s:property value="%{foo}"/>; //int, boolean, etc.
> will not work too.
>
> Best greetings,
> Paweł Wielgus.
>
>
> 2009/12/17 Brian Thompson <el...@gmail.com>:
> > Bwuh?  Just because your fridge doesn't have a built-in toaster, it's
> > worthless?
> >
> > Struts is helpful for stuff you'd want to do on the server side.
> >
> > An easy way to make stuff from the value stack available in javascript is
> to
> > do this in the jsp:
> >
> > <script type="text/javascript">
> >
> > var foo = <s:property value="%{foo}"/>; //int, boolean, etc.
> > var bar = '<s:property value="%{bar}"/>';  //string
> > var bat = '<s:property value="%{foo.bat}"/>';  //string retrieved by
> > foo.getBat()
> >
> > //javascript logic goes here
> >
> > </script>
> >
> > Hope that helps,
> >
> > -Brian
> >
> > On Thu, Dec 17, 2009 at 8:33 AM, Jim Collings <jl...@gmail.com>
> wrote:
> >
> >> So it's impossible?  JavaScript and Struts 2 don't interact at all?
> >> What good is Struts 2 then?
> >>
> >> 2009/12/17 Paweł Wielgus <po...@gmail.com>:
> >> > Hi Jim,
> >> > action is on server side and javascript is on browser side,
> >> > they don't interact, You can generate js server side but that's it.
> >> > Js will be run in browser so it has no access to stack or action
> >> variables.
> >> >
> >> > Best greetings,
> >> > Paweł Wielgus.
> >> >
> >> >
> >> >
> >> > 2009/12/17 Jim Collings <jl...@gmail.com>:
> >> >> So I have two actions and one jsp.  The idea is that one is for the
> >> >> entire page and another is for putting into a <div> via a JavaScript
> >> >> method.
> >> >>
> >> >> Question:  How do I get items off of the value stack for use in
> >> JavaScript?
> >> >>
> >> >>
> >> >> Jim C.
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> 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
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: JavaScript / AJAX + Struts 2?

Posted by Paweł Wielgus <po...@gmail.com>.
Hi Brian,
have You tried running this code?
i have a doubt about:
foo.getBat() line.
As far as i know it will not work.

Also line:
var foo = <s:property value="%{foo}"/>; //int, boolean, etc.
will not work too.

Best greetings,
Paweł Wielgus.


2009/12/17 Brian Thompson <el...@gmail.com>:
> Bwuh?  Just because your fridge doesn't have a built-in toaster, it's
> worthless?
>
> Struts is helpful for stuff you'd want to do on the server side.
>
> An easy way to make stuff from the value stack available in javascript is to
> do this in the jsp:
>
> <script type="text/javascript">
>
> var foo = <s:property value="%{foo}"/>; //int, boolean, etc.
> var bar = '<s:property value="%{bar}"/>';  //string
> var bat = '<s:property value="%{foo.bat}"/>';  //string retrieved by
> foo.getBat()
>
> //javascript logic goes here
>
> </script>
>
> Hope that helps,
>
> -Brian
>
> On Thu, Dec 17, 2009 at 8:33 AM, Jim Collings <jl...@gmail.com> wrote:
>
>> So it's impossible?  JavaScript and Struts 2 don't interact at all?
>> What good is Struts 2 then?
>>
>> 2009/12/17 Paweł Wielgus <po...@gmail.com>:
>> > Hi Jim,
>> > action is on server side and javascript is on browser side,
>> > they don't interact, You can generate js server side but that's it.
>> > Js will be run in browser so it has no access to stack or action
>> variables.
>> >
>> > Best greetings,
>> > Paweł Wielgus.
>> >
>> >
>> >
>> > 2009/12/17 Jim Collings <jl...@gmail.com>:
>> >> So I have two actions and one jsp.  The idea is that one is for the
>> >> entire page and another is for putting into a <div> via a JavaScript
>> >> method.
>> >>
>> >> Question:  How do I get items off of the value stack for use in
>> JavaScript?
>> >>
>> >>
>> >> Jim C.
>> >>
>> >> ---------------------------------------------------------------------
>> >> 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
>>
>>
>

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


Re: JavaScript / AJAX + Struts 2?

Posted by Brian Thompson <el...@gmail.com>.
Bwuh?  Just because your fridge doesn't have a built-in toaster, it's
worthless?

Struts is helpful for stuff you'd want to do on the server side.

An easy way to make stuff from the value stack available in javascript is to
do this in the jsp:

<script type="text/javascript">

var foo = <s:property value="%{foo}"/>; //int, boolean, etc.
var bar = '<s:property value="%{bar}"/>';  //string
var bat = '<s:property value="%{foo.bat}"/>';  //string retrieved by
foo.getBat()

//javascript logic goes here

</script>

Hope that helps,

-Brian

On Thu, Dec 17, 2009 at 8:33 AM, Jim Collings <jl...@gmail.com> wrote:

> So it's impossible?  JavaScript and Struts 2 don't interact at all?
> What good is Struts 2 then?
>
> 2009/12/17 Paweł Wielgus <po...@gmail.com>:
> > Hi Jim,
> > action is on server side and javascript is on browser side,
> > they don't interact, You can generate js server side but that's it.
> > Js will be run in browser so it has no access to stack or action
> variables.
> >
> > Best greetings,
> > Paweł Wielgus.
> >
> >
> >
> > 2009/12/17 Jim Collings <jl...@gmail.com>:
> >> So I have two actions and one jsp.  The idea is that one is for the
> >> entire page and another is for putting into a <div> via a JavaScript
> >> method.
> >>
> >> Question:  How do I get items off of the value stack for use in
> JavaScript?
> >>
> >>
> >> Jim C.
> >>
> >> ---------------------------------------------------------------------
> >> 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
>
>

Re: JavaScript / AJAX + Struts 2?

Posted by Jim Collings <jl...@gmail.com>.
So it's impossible?  JavaScript and Struts 2 don't interact at all?
What good is Struts 2 then?

2009/12/17 Paweł Wielgus <po...@gmail.com>:
> Hi Jim,
> action is on server side and javascript is on browser side,
> they don't interact, You can generate js server side but that's it.
> Js will be run in browser so it has no access to stack or action variables.
>
> Best greetings,
> Paweł Wielgus.
>
>
>
> 2009/12/17 Jim Collings <jl...@gmail.com>:
>> So I have two actions and one jsp.  The idea is that one is for the
>> entire page and another is for putting into a <div> via a JavaScript
>> method.
>>
>> Question:  How do I get items off of the value stack for use in JavaScript?
>>
>>
>> Jim C.
>>
>> ---------------------------------------------------------------------
>> 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


Re: JavaScript / AJAX + Struts 2?

Posted by Paweł Wielgus <po...@gmail.com>.
Hi James,
the code You have shown is generating java script on server side,
and then on browser side you run it in browser.
For example You can't do this:
var myList = '<s:property value="zipCodes"/>';
myList.toUpperCase();
and expect that on server side inside action, zipCodes variable is
updated with new uppereCased value.

Also there is nothing bad in generating js on server side,
i do it all the time. It's just worth knowing that server != browser
in terms of execution space.

Best greetings,
Paweł Wielgus.


2009/12/17 james billa <ja...@gmail.com>:
> Pawel,
>
> I am doing something like shown below and it works good for me. Isn't it
> calling the values from model/stack value from java script?  zipCodes is in
> my model. Please tell me ur option. that would help me underst it better.  I
> am using struts 2.1.6. Thanks.
>
> function showmylist() {
>  var myList = '<s:property value="zipCodes"/>';
>  var seletedzipcodelist = new Array();
>  seletedzipcodelist = myList.split(",");
>  if (seletedzipcodelist != null && seletedzipcodelist != "") {
>   for (i in seletedzipcodelist) {
>    document.getElementById(seletedzipcodelist[i]).className = "showzip";
>   }
>  }
>  document.getElementById("something").value = '<s:property
> value="NewDate"/>';
>  }
>
>
>
> 2009/12/17 Paweł Wielgus <po...@gmail.com>
>
>> Hi Jim,
>> action is on server side and javascript is on browser side,
>> they don't interact, You can generate js server side but that's it.
>> Js will be run in browser so it has no access to stack or action variables.
>>
>> Best greetings,
>> Paweł Wielgus.
>>
>>
>>
>> 2009/12/17 Jim Collings <jl...@gmail.com>:
>> > So I have two actions and one jsp.  The idea is that one is for the
>> > entire page and another is for putting into a <div> via a JavaScript
>> > method.
>> >
>> > Question:  How do I get items off of the value stack for use in
>> JavaScript?
>> >
>> >
>> > Jim C.
>> >
>> > ---------------------------------------------------------------------
>> > 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


Re: JavaScript / AJAX + Struts 2?

Posted by james billa <ja...@gmail.com>.
Pawel,

I am doing something like shown below and it works good for me. Isn't it
calling the values from model/stack value from java script?  zipCodes is in
my model. Please tell me ur option. that would help me underst it better.  I
am using struts 2.1.6. Thanks.

function showmylist() {
  var myList = '<s:property value="zipCodes"/>';
  var seletedzipcodelist = new Array();
  seletedzipcodelist = myList.split(",");
  if (seletedzipcodelist != null && seletedzipcodelist != "") {
   for (i in seletedzipcodelist) {
    document.getElementById(seletedzipcodelist[i]).className = "showzip";
   }
  }
  document.getElementById("something").value = '<s:property
value="NewDate"/>';
 }



2009/12/17 Paweł Wielgus <po...@gmail.com>

> Hi Jim,
> action is on server side and javascript is on browser side,
> they don't interact, You can generate js server side but that's it.
> Js will be run in browser so it has no access to stack or action variables.
>
> Best greetings,
> Paweł Wielgus.
>
>
>
> 2009/12/17 Jim Collings <jl...@gmail.com>:
> > So I have two actions and one jsp.  The idea is that one is for the
> > entire page and another is for putting into a <div> via a JavaScript
> > method.
> >
> > Question:  How do I get items off of the value stack for use in
> JavaScript?
> >
> >
> > Jim C.
> >
> > ---------------------------------------------------------------------
> > 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: JavaScript / AJAX + Struts 2?

Posted by Paweł Wielgus <po...@gmail.com>.
Hi Jim,
action is on server side and javascript is on browser side,
they don't interact, You can generate js server side but that's it.
Js will be run in browser so it has no access to stack or action variables.

Best greetings,
Paweł Wielgus.



2009/12/17 Jim Collings <jl...@gmail.com>:
> So I have two actions and one jsp.  The idea is that one is for the
> entire page and another is for putting into a <div> via a JavaScript
> method.
>
> Question:  How do I get items off of the value stack for use in JavaScript?
>
>
> Jim C.
>
> ---------------------------------------------------------------------
> 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: JavaScript / AJAX + Struts 2?

Posted by Johannes Geppert <jo...@web.de>.
Hello Jim,

if you like to use AJAX with struts2 take a look at the 
build in dojo plugin or to one of the other (jquery, yui) plugins
you can found in the Plugin Registry.

http://cwiki.apache.org/S2PLUGINS/home.html

Best Regards

Johannes Geppert


jcllings wrote:
> 
> So I have two actions and one jsp.  The idea is that one is for the
> entire page and another is for putting into a <div> via a JavaScript
> method.
> 
> Question:  How do I get items off of the value stack for use in
> JavaScript?
> 
> 
> Jim C.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 


-----
---
web: http://www.jgeppert.com
twitter: http://twitter.com/jogep

-- 
View this message in context: http://old.nabble.com/JavaScript---AJAX-%2B-Struts-2--tp26825831p26829058.html
Sent from the Struts - User mailing list archive at Nabble.com.


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