Announcement Announcement Module
Collapse
No announcement yet.
Spring and XSLT Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring and XSLT

    I'm trying to get the Spring and XSLT example in the documenation to work. The documentation has an incomplete example so i'm having a hard time getting it to work. The error message i'm getting is:

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'home' defined in null: Initialization of bean failed; nested exception is org.springframework.context.ApplicationContextExce ption: Can't load stylesheet from ServletContext resource [/WEB-INF/xsl/home.xslt] in XSLT view 'home'; nested exception is javax.xml.transform.TransformerConfigurationExcept ion: Could not compile stylesheet


    I know its loading the stylesheet but I think its not getting the XML object from my HomePage class. What should the link be between the HomePageController class and the HomePage class. Here's my code:

    HomePage.java:

    package xslt;

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

    import javax.servlet.http.*;

    import org.jdom.Element;
    import org.jdom.output.DOMOutputter;
    import org.springframework.web.servlet.view.xslt.Abstract XsltView;
    import org.w3c.dom.Node;

    public class HomePage extends AbstractXsltView {

    protected Node CreateDomNode(
    Map model, String rootName, HttpServletRequest req, HttpServletResponse res
    ) throws Exception{
    org.jdom.Document doc = new org.jdom.Document();
    Element root = new org.jdom.Element(rootName);
    doc.setRootElement(root);

    List words = (List) model.get("wordlist");
    for (Iterator it = words.iterator(); it.hasNext() {
    String nextWord = (String) it.next();
    Element e = new Element("word");
    e.setText(nextWord);
    root.addContent(e);
    }

    return new DOMOutputter().output( doc );
    }
    }

    HomePageController.java

    package xslt;

    import org.springframework.web.servlet.mvc.Controller;
    import org.springframework.web.servlet.ModelAndView;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import java.io.IOException;
    import java.util.Map;
    import java.util.HashMap;
    import java.util.ArrayList;
    import java.util.List;

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;

    public class HomePageController implements Controller {

    /** Logger for this class and subclasses */
    protected final Log logger = LogFactory.getLog(getClass());

    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

    logger.info("returning home.xslt view");

    Map map = new HashMap();
    List wordlist = new ArrayList();

    wordlist.add("hello");
    wordlist.add("world");

    map.put("wordlist", wordlist);

    logger.info(wordlist);

    return new ModelAndView("home", map);
    }
    }

    springapp-servlet.xml

    <beans>
    <bean id="messageSource" class="org.springframework.context.support.Resourc eBundleMessageSource">
    <property name="basename"><value>messages</value></property>
    </bean>

    <bean id="HomePageController" class="xslt.HomePageController"/>

    <bean id="HomePage" class="xslt.HomePage"/>

    <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/home.htm">HomePageController</prop>
    <prop key="/priceincrease.htm">priceIncreaseForm</prop>
    </props>
    </property>
    </bean>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.Resour ceBundleViewResolver">
    <property name="basename">
    <value>views</value>
    </property>
    </bean>
    </beans>

    views.properties

    home.class=xslt.HomePage
    home.stylesheetLocation=/WEB-INF/xsl/home.xslt
    home.root=words

  • #3
    It sounds like your stylesheet is invalid. Make sure any <xsl:imports> and <xsl:includes> are also valid. I've been successfully using extensions to AbstractXsltView for a while as well as my own Xslt view implementations.

    Comment


    • #4
      I've got the same problem.
      Does someone has any suggestions?

      Comment


      • #5
        complete XSLT example?

        The spring documentation for the integration of XSLT views definitely wasn't written for folks new to Java. Assumptions are made and details are glossed over. I would love to see a simple example application that works and is explicit about what's going on.

        Comment

        Working...
        X