title: Pass global variables to Spring + Apache Tiles
body: <p>I'm currently running a working Spring + Apache Tiles webapp.
  I need to show some example code to explain my intention.</p>
  
  <p>Apache Tiles Configuration:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;!DOCTYPE tiles-definitions PUBLIC
      "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
      "http://tiles.apache.org/dtds/tiles-config_2_1.dtd"&gt;
  
  &lt;tiles-definitions&gt;
  
      &lt;definition name="baseLayout" template="/WEB-INF/layouts/www_base.jsp" /&gt;
  
      &lt;definition name="home" extends="baseLayout"&gt;
          &lt;put-attribute name="body" value="/WEB-INF/views/home.jsp" /&gt;
      &lt;/definition&gt;
  
  &lt;/tiles-definitions&gt;
  </code></pre>
  
  <p>Example Controller:</p>
  
  <pre><code>@Controller
  public class ExampleController {
      @RequestMapping("/index.html")
      public String index(Map&lt;String, Object&gt; map) {
          map.put("hello", "world");
          return "home";
      }
  }
  </code></pre>
  
  <p>This would display <code>www_base.jsp</code> with <code>home.jsp</code> as <code>body</code>. I can use variable <code>${hello}</code> in <code>www_base.jsp</code> as well as in <code>home.jsp</code>.</p>
  
  <p>But I don't want to set <code>hello</code> in each Controller method to be able to use it in <code>www_base.jsp</code> on each page.</p>
  
  <p>Is there a way to set global variables for <code>www_base.jsp</code>, e.g. in the constructor of <code>ExampleController</code>?</p>
  
  <p><strong>UPDATE</strong>
  Example Code using a Map</p>
  
  <pre><code>@Controller
  @RequestMapping("/")
  public class BlogController {
      @ModelAttribute
      public void addGlobalAttr( Map&lt;String, Object&gt; map ) {
          map.put("fooone", "foo1");
      }
  
      @RequestMapping("/index.html")
      public String posts(Map&lt;String, Object&gt; map) {
          map.put("foothree", "foo3");
          return "posts";
      }
  }
  </code></pre>