Back Forum Reply New

Getting spring mvc to work with ajaxtags

Hi, I'm relatively new to spring mvc, and I'm trying to add ajax to one of my jsp pages. I have installed ajaxtags, but I can't get them to work. The tag I want to use is the lt;ajax:selectgt; tag. Here is my code:

web.xml

Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;web-app xmlns:xsi=quot;2001/XMLSchema-instancequot;
xmlns=quot;xml/ns/javaeequot; xmlns:web=quot;xml/ns/javaee/web-app_2_5.xsdquot;
xsi:schemaLocation=quot;xml/ns/javaee xml/ns/javaee/web-app_2_5.xsdquot;
id=quot;WebApp_IDquot; version=quot;2.5quot;gt;
lt;display-namegtrojectlt;/display-namegt;
lt;welcome-file-listgt;
lt;welcome-filegt;/WEB-INF/jsp/index.jsplt;/welcome-filegt;
lt;/welcome-file-listgt;
lt;resource-env-refgt;
lt;descriptiongt;Sample Hibernate SessionFactorylt;/descriptiongt;
lt;resource-env-ref-namegt;sessionFactorylt;/resource-env-ref-namegt;
lt;resource-env-ref-typegt;org.hibernate.SessionFactorylt;/resource-env-ref-typegt;
lt;/resource-env-refgt;
lt;servletgt;
lt;servlet-namegt;sourceloaderlt;/servlet-namegt;
lt;servlet-classgt;net.sourceforge.ajaxtags.servlets.SourceLoaderlt;/servlet-classgt;
lt;init-paramgt;
lt;param-namegt;prefixlt;/param-namegt;
lt;param-valuegt;/ajaxtagslt;/param-valuegt;
lt;/init-paramgt;
lt;/servletgt;

lt;servletgt;
lt;servlet-namegtdflt;/servlet-namegt;
lt;servlet-classgt;org..web.servlet.DispatcherServletlt;/servlet-classgt;
lt;load-on-startupgt;1lt;/load-on-startupgt;
lt;/servletgt;
lt;servletgt;
lt;servlet-namegt;Hellolt;/servlet-namegt;
lt;servlet-classgt;org..web.servlet.DispatcherServletlt;/servlet-classgt;
lt;load-on-startupgt;1lt;/load-on-startupgt;
lt;/servletgt;
lt;servletgt;
lt;servlet-namegt;ajaxlt;/servlet-namegt;
lt;servlet-classgt;org..web.servlet.DispatcherServletlt;/servlet-classgt;
lt;load-on-startupgt;1lt;/load-on-startupgt;
lt;/servletgt;

lt;servlet-mappinggt;
lt;servlet-namegt;ajaxlt;/servlet-namegt;
lt;ucl-patterngt;*.controllerlt;/ucl-patterngt;
lt;/servlet-mappinggt;
lt;servlet-mappinggt;
lt;servlet-namegtdflt;/servlet-namegt;
lt;ucl-patterngt;*.pdflt;/ucl-patterngt;
lt;/servlet-mappinggt;
lt;servlet-mappinggt;
lt;servlet-namegt;Hellolt;/servlet-namegt;
lt;ucl-patterngt;*.htmlt;/ucl-patterngt;
lt;/servlet-mappinggt;
   
lt;/web-appgt;
ajax-servlet.xml

Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;beans xmlns=quot;schema/beansquot;
xmlns:xsi=quot;2001/XMLSchema-instancequot;
xsi:schemaLocation=quot;schema/beans schema/beans/spring-beans-2.5.xsdquot;gt;
lt;bean id=quot;beanNameResolverquot;
class=quot;org..web.servlet.view.BeanNameViewResolverquot; /gt;
lt;bean id=quot;ajaxViewquot; class=quot;packet.Ajaxquot; /gt;
lt;bean id=quot;ajaxctrquot; class=quot;packet.AjaxControlerquot; /gt;
lt;bean id=quot;uclMappingquot;
class=quot;org..web.servlet.handler.SimpleuclHandlerMappingquot;gt;
lt;property name=quot;mappingsquot;gt;
lt;propsgt;
lt;prop key=quot;/AjaxControler.controllerquot;gt;ajaxctrlt;/propgt;
lt;/propsgt;
lt;/propertygt;
lt;/beangt;
lt;/beansgt;
newPublication.jsp (the 2 combo boxes and the ajax tag)

Code:
lt;tr bgcolor = quot;#E6E8FAquot;gt;
lt;td align=quot;rightquot;gt;#1054;#1073;#1083;#1072;#1089;#1090; :lt;/tdgt;
lt;td colspan=quot;2quot;gt;lt;select name=quot;oblquot;gt;
lt;c:forEach var=quot;jquot; items=quot;${OL}quot;gt;
lt;option value=quot;${j.id}quot;gt;${j.ime}lt;/optiongt;
lt;/c:forEachgt;
lt;/selectgt;lt;/tdgt;
lt;/trgt;
lt;tr bgcolor = quot;#E6E8FAquot;gt;
lt;td align=quot;rightquot;gt;#1055;#1086;#1076;#1086;#1073;#1083;#1072;#1089;#1090; :lt;/tdgt;
lt;td colspan=quot;2quot;gt;lt;form:select path=quot;podoblastquot;gt;
lt;formptions items=quot;${POL}quot; itemLabel=quot;imequot; itemValue=quot;idquot; /gt;
lt;/form:selectgt;lt;/tdgt;
lt;/trgt;
lt;ajax:select baseucl=quot;AjaxControler.controllerquot; source=quot;oblquot; target=quot;podoblastquot; parameters=quot;id={j.id}quot; postFunction=quot;doOtherThingsquot; /gt;The ControllerCode:
package packet;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import java_classes.Podoblast;
import java_classes.PodoblastMenager;

import javax.servlet.from.fromServletRequest;
import javax.servlet.from.fromServletResponse;

import org..web.servlet.ModelAndView;
import org..web.servlet.mvc.AbstractController;

public class AjaxControler extends AbstractController{

@Override
protected ModelAndView handleRequestInternal(fromServletRequest request,
fromServletResponse response) throws Exception {
System.out.println(quot;jajajquot;);
Maplt;String, Objectgt; map = new HashMaplt;String, Objectgt;();
int id = Integer.parseInt(request.getParameter(quot;idquot;));
PodoblastMenager pod = new PodoblastMenager();
Listltodoblastgt; lista = (Listltodoblastgt;)pod.getPodoblastList();
Listltodoblastgt; selected = new LinkedListltodoblastgt;();
for(Podoblast p:lista){
if(p.getOblast().getId() == id){
selected.add(p);
}
}
map.put(quot;listquot;, lista);
return new ModelAndView(quot;xmlViewquot;, map);
}}
The View

Code:
package packet;

import java.util.List;
import java.util.Map;

import java_classes.Podoblast;
import java_classes.PodoblastMenager;

import javax.servlet.ServletOutputStream;
import javax.servlet.from.fromServletRequest;
import javax.servlet.from.fromServletResponse;

import net.sourceforge.ajaxtags.xml.AjaxXmlBuilder;

import org..web.servlet.view.AbstractView;

public class Ajax extends AbstractView{
@Override
protected void renderMergedOutputModel(Map map, fromServletRequest request,
fromServletResponse response) throws Exception {
Listltodoblastgt; lista = (Listltodoblastgt;)map.get(quot;listquot;);
AjaxXmlBuilder build = new AjaxXmlBuilder();
for(Podoblast p:lista){
build.addItem(p.getId() + quot;quot;, p.getIme());
}
String xml = build.toString();
ServletOutputStream out = response.getOutputStream();
out.print(xml);
out.close();
}
}
I've tried to configure it following this thread showthread.php?t=69832, but it doesn't seem to work.
Can anyone spot my mistake, or maybe post a working code in reply?
Thanks in advance!
¥
Back Forum Reply New