Menu

Spring & XML+XSLT as the view ?

John Cobo
2003-10-31
2003-11-11
  • John Cobo

    John Cobo - 2003-10-31

    Has anybody combined Spring with XML+XSLT instead of JSP/velocity,... ?  I'd love to see an example.

     
    • Rod Johnson

      Rod Johnson - 2003-10-31

      You need to extend org.springframework.web.servlet.view.xslt.XsltView and implement the following method:

      protected abstract Node createDomNode(Map model, String root, HttpServletRequest request, HttpServletResponse response) throws Exception

      You can then specify this in the views.properties file or wherever you define your view. There's a stylesheet JavaBean property.

      I did talk about Domify in my book and provided a concrete class that used it to generate XML from model beans on the fly, but AFAICT that project seems to be just about dead (although in fairness I haven't checked for a month or two) and there were problems with cyclic references that they haven't fixed.

      If you wanted to use Castor or Domify or something you could supply a concrete subclass.

      Regards,
      Rod

       
    • ultan ocarroll

      ultan ocarroll - 2003-11-04

      John,

      Im doing some XSLT with it at the moment. Written my own XSLTView implementation as I needed to have a composite template - kind of Tiles, but simpler I think.

      Anyway, Ive managed to get it up and running (its goign to be a re-deploy of an existing app), so if you have specific quesions .....

       
    • John Cobo

      John Cobo - 2003-11-06

      Ultan,

      Super, I thought somebody must have been here before me.

      Specific questions:

      1) 'Tiles' - I was a fan of Tiles and also wanted to
      do something similar with XSLT.  Thus far I have only bothered to 'include' fragments of the page into a main page which is not as nice as the way Tiles works.  I'd be interested to see how you did it if you are willing to share.   :)

      2) XSLT with Spring - Rod's response in the forum went right over my head.  I was thinking one could just direct a http request to some JAVA that would (1) get some data into XML,
      (2) run a XSLT transfor or two,
      (3) spit resulting html back to the browser.  An example putting it all together would really help.

      3) XSLT and Forms - Whlle XSLT appears great for
      displaying data and including links, I have not yet figured out how to do forms with it.  Spring and struts provide ways of collecting and validating form data but both seem to tie in the form with
      the framework.  Have you tackled this ?  Does one
      'simply' pass form actions/html through the XSLT to the client ?

      Any help would be much appreciated.  It does seem to me that XSLT will play a big part in the future for web applications (I hope).

      John C.

       
    • ultan ocarroll

      ultan ocarroll - 2003-11-11

      John - been away hacking.

      1) not doing tiles, got too much to do at the mo' and static attributes are doing it for me so far. Will look into tiles in the near future - it sounds like what I want.

      2) yup - you need to
      i)implement a class that returns a ModelAndView, that you can call from your controller, just as in the example code.

      ii) extend AbstractXsltView : all you need to then is write code to implement

      protected Node createDomNode(Map model, String root, HttpServletRequest request, HttpServletResponse response) throws Exception

      - its in here that you do whatever you need to do to convert form the java objects in the model object to create the XML document that gets transformed.

      Ive done this but also abstracted the workflow a little further - Ive created a method that takes my named template in views.xml, and creates a new stylesheet with myStatic attributes being the href values for the <xsl:include> tags. I then reset the templates source, and mark it as done so I dont do this step again.

      That way, once the XML is generated and the code hands back to the template/abstract class that does the transform, Ive got my dynamic elements (the hrefs) resolved in the XSL and Ive got the input in the form of the XML.

      3) All Id do, on the face of it, is have the XSLT write the HTML that sets the POST or GET action to point another view somewhere. This not what you mean ?

       

Log in to post a comment.

MongoDB Logo MongoDB