Hi, I am finding that <wicket:component> doesn't add stylesheet link in
<head> from add(HeaderContributor). Is there any way to make it work?

I want to use <wicket:component> because can I add border around without
changing my component hierarchy.  If I add my border component in .java, it
works as expected but is something I rather not do in this situation:  I am
adding border around in base page and I don't want the child page to know
and just work as if no border component is added.

Here is a small case to demonstrate:

SomePage.java

import org.apache.wicket.markup.html.WebPage;

public class SomePage extends WebPage {
    public SomePage() {
//        add(new MyBorder("box"));   // this work
    }

}


SomePage.html

<html>
<head></head>
<body>
    <wicket:component class="com.mycompany.MyBorder">
        <p>You should see a yellow background<br/>
           and a red border</p>
    </wicket:component>

<!--    <span wicket:id="box">This is a box</span> -->  <!-- if this is use,
stylesheet show up -->
</body>
</html>


MyBorder.java

public class MyBorder extends Border {
    private static final long serialVersionUID = 1L;
    public MyBorder(String id)  {
        super(id);
        add(getCssContributor());
    }

    protected HeaderContributor getCssContributor()  {
        return HeaderContributor.forCss(MyBorder.class, "style.css");
    }
}


MyBorder.html

<html>
  <body>
    <wicket:border>
      <div class="box_me_up">
         <wicket:body/>
      </div>
    </wicket:border>
  </body>
</html>


style.css

.box_me_up {
    margin: 5px;
    padding: 5px;
    background: yellow;
    border: 2px solid red;
}

Reply via email to