Announcement Announcement Module
No announcement yet.
Return rendered Tiles view as String - including views Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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:

    "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?

    	public void render(Map model, HttpServletRequest request,
    			HttpServletResponse response) throws Exception {
    		// get the tiles view as a string
    		TilesView view = new TilesView();
    		//view.render(model, request, response);

  • #2
    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...