Ajax
要不要更高级的功能?那我们就来看看Stripes是怎么处理Ajax的。我们将把先前的Hello World例程改成使用Ajax调用Stripes动作。本例子的源代码可以在本文资源中找到。首先,我们对Hello.jsp作改动使其引用Prototype JavaScript函数库。我们还要为Ajax调用增加一个JavaScript函数,并更改提交按钮为其添加一个onclick事件:
<%@ taglib prefix="stripes" uri="http://stripes.sourceforge.net/stripes.tld" %> ...... <script src="${pageContext.request.contextPath}/js/prototype.js" type="text/javascript"> </script> <script type="text/javascript"> function sayHelloAjax(){ var myAjax = new Ajax.Updater('hello', "<stripes:url beanclass="com. myco. web. stripes. action. example. HelloWorldAction" event="sayHelloAjax"/>", { method: 'get', parameters: Form.serialize('helloForm') }); } </script> ...... <stripes:errors/> <stripes:form beanclass="com. myco. web. stripes. action. example. HelloWorldAction" id="helloForm"> Say hello to: <br> First name: <stripes:text name="person.firstName"/><br> Age:<stripes:text name="person.age"/><br> <stripes:button name="helloAjax" value="Say Hello" onclick="sayHelloAjax()"/> <div id="hello"></div> </stripes:form> ......
(编辑:aniston)
|