Lets stir some Ajax wizardry into a conventional Struts application, without all the sweat and bother of writing our own JavaScript. Struts 1 and Struts 2 both support Ajax taglibs that look and feel just like ordinary JSP tags. If it's just a little bit of Ajax that you want, these tags will get you around the learning curve in record time.
32. < html > < head > < title > Simple Hello World Example </ title > </ head > < body > < input id = "hello-button" type = "button" value = "Say Hello World via AJAX" /> < br />< br /> < div id = "hello-div" ></ div > </ body > </ html > index.jsp
33. <%@ taglib prefix = "ajax" uri = "javawebparts/ajaxparts/taglib" %> < html > < head > < title > Simple Hello World Example </ title > </ head > < body > < input id = "hello-button" type = "button" value = "Say Hello World via AJAX" /> < ajax:event attachTo = "hello-button" ajaxRef = "index/hello-button" /> < br />< br /> < div id = "hello-div" ></ div > < ajax:enable /> </ body > </ html > index.jsp
34. ajax-config.xml < ajaxConfig > < group ajaxRef = "index" > < element ajaxRef = "hello-button" > < event type = "onclick" > < requestHandler type = "std:SimpleRequest" target = " index-result.txt " > < parameter /> </ requestHandler > < responseHandler type = "std:InnerHTML" > < parameter > hello-div </ parameter > </ responseHandler > </ event > </ element > </ group > </ ajaxConfig >
35. Hello World! I am an AJAX result from the (mock) server. index-result.txt
53. < ajaxConfig > < group ajaxRef = " index " > < element ajaxRef = " hello-button " > < event type = "onclick" > < requestHandler type = "std:SimpleRequest" target = " index-result.action " > < parameter /> How does AjaxParts work? <body> < input id = "hello-button" type = "button" value = "Say Hello World via AJAX" /> < ajax:event attachTo = "hello-button“ ajaxRef = " index/hello-button " />
54. < responseHandler type = "std:InnerHTML" > < parameter > hello-div </ parameter > </ responseHandler > < br />< br /> < div id = " hello-div " ></ div > </ body > < ajax:enable /> How does AjaxParts work?
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76. <%@ taglib prefix = "yui" uri = "/struts-yui-tags" %> <%@ taglib prefix = "s" uri = "/struts-tags" %> < html > < head > < yui:head datepicker = "true" /> </ head > < body > < p > The selected date is < s:property value = "datepicker" /></ p > < s:form action = "datepicker" > < yui:datepicker id = "datepicker" name = "datepicker" /> < s:submit /> </ s:form > </ body > </ html > datepicker.jsp
77. < action name = "datepicker" class = "actions.Datepicker" > < result > datepicker.jsp </ result > </ action > struts.xml
78. public class Datepicker extends ActionSupport { private Date datepicker ; public Date getDatepicker() { return datepicker ; } public void setDatepicker(Date value) { datepicker = value; } } actions.DatePicker.java