Results 1 to 4 of 4

Thread: Ajax + Tiles issues

  1. #1
    Join Date
    May 2009
    Posts
    4

    Default Ajax + Tiles issues

    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:
    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)
    I'm using the most recent version of Spring (2.5.6), Spring Web Flow (2.0.7) and Tiles (2.1.2).

    The code of the project is below. I tried to keep it as small as possible.

    dispatcher-servlet.xml
    Code:
    <?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>
    tiles-layout.xml
    Code:
    <?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>
    views.properties
    Code:
    home.class=org.springframework.web.servlet.view.tiles2.TilesView
    home.url=home
    
    about.class=org.springframework.web.servlet.view.tiles2.TilesView
    about.url=about
    regularroot.jsp
    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>
    I also think the documentation for using ajax with spring could be improved. Also the documentation for spring-js is almost non-existent.


    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.
    Last edited by Eddy Dean; Jun 20th, 2009 at 03:50 AM.

  2. #2
    Join Date
    Nov 2006
    Location
    Columbus, OH
    Posts
    143

    Default

    Eddy Dean,

    Be it far from me to say what to use, but there have been many discussions regarding the usage of Spring 2.5.x and Tiles 2.1.x. The general consensus leads to ultimately two conclusions:

    1. Writing a new Tiles Configurer for Tiles 2.1.x and Spring 2.5.x
    2. Downgrading Tiles to 2.0.x until Spring 3.0.x is stable


    It appears that you've done the first option, so I'll let that be a decision for you. I've run into a similar problem, though it was a couple months ago, and I seem to remember having to add the requestContextAttribute property to my viewResolver to clear it up. Although it might not help, it's at least a suggestion.

    For yours, it might look something like:

    Code:
      <bean id="tilesViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAjaxTilesView"/>
        <property name="requestContextAttribute" value="requestContext" />
      </bean>
    Hope that helps,
    Regards,

    Joshua Preston

    --

    "The Guide says that there is an art to flying," said Ford, "or rather a knack. The knack lies in learning how to throw yourself at the ground and miss."

  3. #3

    Default Any more info

    Hi there,

    Has anyone got any further with this?

    I am getting the same error when using Spring 3, Spring Web Flow 2.0.8Release and Tiles 2.1.3

    Eggsy

  4. #4

    Default JIRA Ticket with info

    I have noticed the JIRA ticket which includes a view resolver that fixes the issue but has there not been any further action on this?

    JIRA Ticket URL:
    https://jira.springsource.org/browse...mment-tabpanel

    Eggsy

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •