i would like to add this to the tutorial page: please eval.....
tibi -------------------------------------------------------------------------------------------------------- this part is an extension on the following fine tutorial: http://cwiki.apache.org/S2WIKI/struts-2-spring-2-jpa-ajax.html take care the tutorial does not do anything apart from demonstrating the working of ajax. the java code is prototype only. this tutorial misses out on 3 things: 1a) integration it within appfuse setup, taking care of the dojo files 1b) integration it within appfuse setup, taking care of the importing order of the js files 2) getting it working with the decorator, or better without ;) 1a) the dojo files can't be run from the sturts.jar file. to solve this open the struts2-core-2.0.6.jar copy the dojo folder into src/main/webapp/struts/dojo open your web.xml and make sure the staticFIlter is including the right folder: <filter> <filter-name>staticFilter</filter-name> <filter-class>org.appfuse.webapp.filter.StaticFilter</filter-class> <init-param> <param-name>includes</param-name> <param-value>/struts/dojo/*</param-value> </init-param> </filter> 1b) make sure the dojo files are imported first. to do this open your /src/main/webapp/decoraters/default.jsp file and add this line above! all other js imports: <s:head theme="ajax" debug="true"/> (otherwise it will conflict with atleast the scriptaculous.js) 2) make sure your ajax return string will not be decorated. there are many option but i like to do this: open your decorators.xml file: <decorators defaultdir="/decorators"> <excludes> <pattern>/*ajax=true*</pattern> <pattern>/*decorate=false*</pattern> <pattern>/struts/dojo/*</pattern> <!-- OK to remove if you're not using Struts --> <pattern>/resources/*</pattern> </excludes> <decorator name="default" page="default.jsp"> <pattern>/*</pattern> </decorator> </decorators> i added the decorate=false part. urls with this parameter will not be decorated. so an example would be nice right: below an ajaxTest.jsp page which will be the caller. than an ajaxReturn.jsp page which will be the returned data. i expect you can make an AjaxAction with the methods String ajax(), getPersons() etc..by your self. than this is connected by struts like this: -------------------------------------------------------- <action name="ajax" class="ajaxTest"> <result>/WEB-INF/pages/employee/ajaxTest.jsp</result> <result name="ajax">/WEB-INF/pages/employee/ajaxReturn.jsp</result> </action> ------------------------------------------------------- the ajaxTest.jsp: <%@ taglib prefix="s" uri="/struts-tags"%> <head> <script type="text/javascript"> dojo.event.topic.subscribe("/edit", function(data, type, request) { alert("type: "+type); alert("data: "+data); if(type="load"){ document.getElementById("result").innerHTML=data; } }); </script> </head> <!-- URL link to struts action--> <s:url id="ajaxText" action="ajax" method="ajax" > <s:param name="decorate" value="false" /> </s:url> <!-- Div where content will be displayed --> <s:div theme="ajax" id="weather" href="${ajaxText}"> loading content... from the ajax action the ajax method is called. than the ajaxReturn.jsp is rendered here. </s:div> <p>Persons</p> <s:if test="persons.size > 0"> <table> <s:iterator value="persons"> <tr id="row_<s:property value="id"/>"> <td> <s:property value="firstName" /> </td> <td> <s:property value="lastName" /> </td> <td> <!-- call the remove method on the ajax action no return--> <s:url id="removeUrl" action="ajax" method="remove"> <s:param name="id" value="id" /> <s:param name="decorate" value="false" /> </s:url> <s:a href="%{removeUrl}" theme="ajax" >Remove</s:a> <!-- call the edit method an the ajax action. the result (ajaxResult.jps) will be handed to the edit javascript mothed attached to dojo (above) --> <s:url id="editUrl" action="ajax" method="ajax"> <s:param name="id" value="id" /> <s:param name="decorate" value="false" /> </s:url> <s:a href="%{editUrl}" id="a_%{id}" theme="ajax" notifyTopics="/edit">Edit</s:a> </td> <td> <a href=ajax!remove.html?id=2>remove me no ajax</a> </td> </tr> </s:iterator> </table> </s:if> <hr> <div id=result></div> ------------------------------------------------------------------------------------------------------------------------------ the ajaxResult.jsp: <%@ taglib prefix="s" uri="/struts-tags"%> Make some nice form here. Now show all persons. <s:iterator value="persons"> <table><tr><td><s:property value="firstName" /></td> <td><s:property value="lastName" /></td> </tr> </table> </s:iterator> ------------------------------------------------------------------------------------------------------------------------ ok here is my action to: package nl.incipio.match.webapp.action; import java.util.List; import org.appfuse.model.User; import com.opensymphony.xwork2.Preparable; import nl.incipio.match.util.MyBaseAction; public class AjaxTestAction extends MyBaseAction implements Preparable { private static final long serialVersionUID = 378605805550104346L; private List<User> persons; private Long id; @Override public String execute() throws Exception { log.debug("just getting the stuf"); persons = (List<User>) getRequest().getAttribute("persons"); if (persons == null) { log.debug("just ones please"); persons = userManager.getUsers(null); getRequest().setAttribute("persons", persons); } else { log.debug("persons" + persons.size()); } return SUCCESS; } public List<User> getPersons() { return persons; } public void setPersons(List<User> persons) { this.persons = persons; } public String remove() throws Exception { log.debug("do some removing here when i feel like it id:" + id); if (persons != null) { log.debug("before persons" + persons.size()); persons.remove((id.intValue() - 1)); log.debug("after persons" + persons.size()); } return SUCCESS; } public String save() throws Exception { log.debug("do some saving here when i feel like it"); return execute(); } public String ajax() { log.debug("ajax is doing something id:"+id); return "ajax"; } public String edit() throws Exception { log.debug("do some editing here when i feel like it"); return execute(); } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public void prepare() throws Exception { log.debug("i'm getting prepared!!!"); } } ------------------------------------------------------------------ spring config in applicationContext.xml: <bean id="ajaxTest" class="nl.incipio.match.webapp.action.AjaxTestAction"> <property name="userManager" ref="userManager"/> </bean> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
