So I decided to make my own and hopefully this will help others like me who struggled for days to get a grip of the 2 beasts (or beauties).
1. Download the the sample zip file from Struts 2 page here (this is a maven archetype by the way) and unzip.
2. I use Netbeans (6.8) as my IDE (you can also use Eclipse if you know how). Open the project (in Netbeans it is File -> Open Project ->location of the unzipped file ->Coding_Actions_Struts2_Mvn and click the Open Project button).
3. Download jQuery library. Put it in the Web Pages folder.
4. Download json2.js (needed for stringify and parse). Put it in the Web Pages folder.
Inspecting the project, you get to see that a lot is already available. Feel free to look around and see what is already available (click the figure below to see actual layout).
Important: You MUST make sure that all the libraries (jar files) are available, just to make sure right click Libraries and click Download Missing Dependencies.
Now let's edit some files:
#right click Libraries and click Download Missing Dependencies.
- add the following
I only retained the <s:form> for input and removed the <a> links
Create the client.js file and put it in the Web Pages folder.
client.js is where we will put our Ajax goodies #see the attached code
edit the package name to extend the json-default
<package name="basicstruts2" extends="struts-default,json-default">
change the result to this:
That's IT. You dont even need to change the Action classes.
Try it out.
Tip: try it out in firefox and download the firebug plugin to see the ajax posting (I have not added a loading gif to see if anything is processing)
And don't forget to spread the link.
Here is the complete source code