Results 1 to 2 of 2

Thread: Return rendered Tiles view as String - including views

  1. #1
    Join Date
    Jan 2009
    Posts
    23

    Default Return rendered Tiles view as String - including views

    I am trying to create a custom JSON view.
    I have created a class implementing View and I was planning on writing the output in the render method.

    The JSON should something like this:

    Code:
    "errors": "true/false",
    "content": "<p>Some html content<p>"
    The 'content' needs to come from a Tiles view.
    In the new view class I was creating (in the render method) I need to know how to return the rendered content of a TilesView as a String so I can append it to my JSON message.

    Can someone please give me a few pointers?

    Code:
           @SuppressWarnings("unchecked")
    	@Override
    	public void render(Map model, HttpServletRequest request,
    			HttpServletResponse response) throws Exception {
    		
    		// get the tiles view as a string
    		TilesView view = new TilesView();
    		view.setUrl(tilesView);
    		//view.render(model, request, response);
    	}
    thanks

  2. #2
    Join Date
    Jan 2009
    Posts
    23

    Default Still not there yet....Help please

    After reading another post I saw someone else was trying to do something similar. They ended up using a MockHttpServletRequest and MockHttpServletResponse within the controller to obtain the rendered view as a String, calling the method getContentAsString() on the mock response.

    This doesn't seem too elegant, but I got it to work.

    The main problem I don't like is it makes a new mock request to another controller.

    I really just want the existing request to trigger multiple jsps / tiles.
    Tiles does this when you return a tiles definition name, the template usually includes multiple jsp fragments. I'm looking for this behavior within the controller.

    Is there a way to explicitly say render the view in "/web-inf/jsp/pageA.jsp" then include the page in "web-inf/jsp/pageB.jsp"?

    Help please...

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
  •