model view controller - Setting page title dynamically with tiles2 and spring mvc -


I have been asking this question for myself for a long time and I have not found a good solution for this on the web.

That's why I'm using tiles 2 and Spring MVC and I want to set the page title dynamically within the body tile. Is there any way?

  & lt; Definition name = "main template" template = "/ web-nf / template / main.jsp" & gt; & Lt; Put-attribute name = "header" value = "/ WEB-INF / templates / haired.jsp" /> & Lt; Put-attribute name = "footer" value = "/ WEB-INF / templates / pastor.jsp" /> & Lt; Put-attribute name = "body" value = "/ WEB-INF / template / empty .jsp" /> & Lt; / Definition & gt; & Lt; Definition name = "list" expanded = "main theme" & gt; & Lt; Put-attribute name = "body" value = "/ WEB-INF / jsp / list.jsp" /> & Lt; / Definition & gt;   

My current solution is setting the title within the controller

  model.addAttribute ("pageTitle", "blubb");   

and are doing the AC:

tiles in the template Technique

If "I want to set the page title to be dynamically set", "I want to set the page title based on the tile which is being displayed and I do it to tile Feature "then:

  1. Define a title asset; Something like this: & lt; Put-attribute name = "pageTitle" value = "title" />
  2. Page title in page layout for reference; Something like this: & gt; Title & gt; & Lt; Tiles: getAsString property = "pageTitle" /> gt; & Gt; Title & gt;
  3. Set the page title property in any tile, which matters; & Lt; Definition blah blah blah & gt; Put-attribute name = "pageTitle" value = "blah blah blah" & gt; & Lt; / Definition & gt;

    Convertible technique

    The easiest way to do this technique is to add an attribute in the model and for reference with an L expression according to the reference, for example,

    You can do this in your controller:

     string page title; PageTitle = "Something"; Model.add ("PageTitle", page title);  

    Then refer to the "PageTitle" attribute in your page like this:

     & lt; Head & gt; & Lt; Title & gt; $ {PAGETITLE} & lt; / Title & gt;  

    You can use c: in this way:

     & lt; Head & gt; & Lt; Title & gt; & Lt; C: out value = "$ {PageTitle}" /> gt; & Lt; / Title & gt;   

Comments