title: Wicket - Add body tag attribute
body: <p>I'm stuck -</p>
  
  <p>I need to have a Wicket Panel be able to add a class attribute to the &lt;body&gt; tag of whatever page it's on.
  Example usage:</p>
  
  <p>Java:</p>
  
  <pre><code>add(new SpecialSidebarComponent("sidebar"));
  </code></pre>
  
  <p>Generated HTML:</p>
  
  <pre><code>&lt;body class="sidebar"&gt;
     ...
     &lt;div id="sidebar"&gt;My Wicket Panel&lt;/div&gt;
     ...
  &lt;/body&gt;
  </code></pre>
  
  <p>I cannot add a wicket:id and make the body a Wicket component, because this makes it very difficult to add components to a page in the big page hierarchy I have, and it still also doesn't easily allow for a Panel to modify the body attribute.</p>
  
  <p>I thought BodyTagAttributeModifier may be for this, but apparently it is for something else and cannot get it to function ( <a href="https://stackoverflow.com/questions/1247820/wicket-how-to-use-the-bodytagattributemodifier-class">Wicket: how to use the BodyTagAttributeModifier class?</a> )</p>
  
  <p>Any helpful ideas?</p>
  
  <p>Update:</p>
  
  <p>In looking at it, it appears the BodyTagAttributeModifier class is <em>only</em> for a Panel's parent tag, not the Page's &lt;body&gt; tag:</p>
  
  <p>Example (Scala syntax):</p>
  
  <pre><code>class Home extends WebPage {
    add(new Sidebar("sidebar"))
  }
  class Sidebar(id: String) extends Panel(id) {
    add(new BodyTagAttributeModifier("class", true, new Model("layout-class"), getParent))
  }
  </code></pre>
  
  <p>Template:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
      &lt;div wicket:id="sidebar"&gt;Sidebar&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Rendered:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
      &lt;div class="layout-class"&gt;
          &lt;h1&gt;Hello World!&lt;/h1&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Very confusing name IMHO.   Doesn't solve the issue but at least makes more sense.</p>