I can't seem to get AJAX working properly with spring-js and tiles. I have created a small sample project with only two pages ("home" and "about us"), and I tried to let it reload only the contents of the page when a link is clicked, instead of the entire page.
While displaying the pages by typing the URLs in the address bar of the browser works just fine, clicking the ajax links does not. Appending ?fragments=content to the url seems to get ignored by the application, it has no influence on page rendering. When an ajax link is clicked an error page sort of "pops up" (gets overlayed on the browser window, I blame dojo). The error page shows the following trace:
I'm using the most recent version of Spring (2.5.6), Spring Web Flow (2.0.7) and Tiles (2.1.2).Code:exception org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:583) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390) root cause java.lang.NullPointerException org.springframework.js.ajax.tiles2.AjaxTilesView.renderMergedOutputModel(AjaxTilesView.java:92) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:257) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1183) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:902) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
The code of the project is below. I tried to keep it as small as possible.
dispatcher-servlet.xml
tiles-layout.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:flow="http://www.springframework.org/schema/webflow-config" xmlns:sec="http://www.springframework.org/schema/security" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd"> <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basename" value="/WEB-INF/classes/messages"/> <property name="cacheSeconds" value="60"/> <property name="defaultEncoding" value="UTF-8"/> </bean> <bean id="tilesViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver"> <property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAjaxTilesView"/> </bean> <bean id="tilesConfigurer" class="tool.SpringTilesConfigurer"> <property name="definitions"> <list> <value>/WEB-INF/tiles-layout.xml</value> </list> </property> </bean> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <value> /**/home.htm=homeController /**/about.htm=aboutController </value> </property> </bean> <bean id="homeController" class="tool.RegularController"> <property name="viewName" value="home"/> <property name="titleKey" value="homepage.title"/> </bean> <bean id="aboutController" class="tool.RegularController"> <property name="viewName" value="about"/> <property name="titleKey" value="aboutpage.title"/> </bean> </beans>
views.propertiesCode:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" "http://tiles.apache.org/dtds/tiles-config_2_0.dtd"> <tiles-definitions> <definition name="home" template="/WEB-INF/views/regularroot.jsp"> <put-attribute name="content" value="home.content"/> </definition> <definition name="home.content" template="/WEB-INF/views/home.jsp"> </definition> <definition name="about" template="/WEB-INF/views/regularroot.jsp"> <put-attribute name="content" value="about.content"/> </definition> <definition name="about.content" template="/WEB-INF/views/about.jsp"> </definition> </tiles-definitions>
regularroot.jspCode:home.class=org.springframework.web.servlet.view.tiles2.TilesView home.url=home about.class=org.springframework.web.servlet.view.tiles2.TilesView about.url=about
I also think the documentation for using ajax with spring could be improved. Also the documentation for spring-js is almost non-existent.Code:<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%> <%@taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="<c:url value="/resources/dojo/dojo.js" />"> </script> <script type="text/javascript" src="<c:url value="/resources/spring/Spring.js" />"> </script> <script type="text/javascript" src="<c:url value="/resources/spring/Spring-Dojo.js" />"> </script> <title> <c:out value="${titleKey}"/> </title> </head> <body> <h1><c:out value="${titleKey}"/></h1> <ul id="menu"> <li> <a href="<c:url value="home.htm"/>" id="home">Home</a> </li> <li> <a href="<c:url value="about.htm"/>" id="about">About us</a> </li> <script type="text/javascript"> Spring.addDecoration(new Spring.AjaxEventDecoration({ elementId: "about", event: "onclick", params: { fragments:"content" } })); Spring.addDecoration(new Spring.AjaxEventDecoration({ elementId: "home", event: "onclick", params: { fragments:"content" } })); </script> </ul> <div id="content"> <tiles:insertAttribute name="content"/> </div> </body> </html>
Thanks in advance,
Eddy Dean
---- EDIT ----
I've been reading through the source of org.springframework.js.ajax.tiles2.AjaxTilesView, and it seems that it uses quite a lot deprecated methods, which causes the NullPointerException. The problem seems to be that BasicTilesContainer.getContextFactory is deprecated and always returns null.


Reply With Quote
