Notes on working with JavaScript / AJAX & Struts 2 Edit

The original thread of discussion for this can be found here.

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


I tried this but missed the ' marks because it's been so long since I did any JavaScript. This doesn't work in script files but may in embedded scripts.

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 in the process.
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!");

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

//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");"block";
 if (request.readyState == 4)
   d.innerHTML = request.responseText ;"none";

Jcllings 06:45, January 24, 2010 (UTC)

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.