struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Collings <jlistn...@gmail.com>
Subject Re: JavaScript / AJAX + Struts 2?
Date Fri, 18 Dec 2009 12:37:49 GMT
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 <jlistnews@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


Mime
View raw message