2012-12-13

Example of Wicket's markup inheritance – wicket:child and wicket:extend

This is the most clean way of composing the pages content in Wicket.

Base page

01.<html>
02.  <body>
03.    <h1>My Web</h1>
04. 
05.    <div class="content">
06.      <wicket:child />
07.    </div>
08. 
09.    <div>(c) 2010 Ondra.Zizka.cz</div>
10.  </body>
11.</html>
1.public class BaseLayoutPage extends WebPage { ... }

Child page

01.<html>
02.  <body>
03.    <h1>Child page</h1>
04. 
05.    DON'T get disturbed by this content, it's in examples only to confuse you.
06.    *** Everything outside "wicket:extend" will be ignored. ***
07. 
08.    <wicket:extend>
09.      <h2>News</h2>
10.      So this is the real content to be included into the base page.
11. 
12.      Here we have some component container:
13. 
14.      <div wicket:id="news">Works like usual, so this will be replaced by the component's stuff.</div>
15. 
16.    <wicket:extend>
17. 
18.    *** Again, everything outside the wicket:extend is ignored. ***
19. 
20.    <div>(c) 2010 Ondra.Zizka.cz</div>
21.  </body>
22.</html>
1.public class NewsPageContent extends BaseLayoutPage {
2.  public NewsPageContent(){
3.    add( new Label("news", "Good news everyone!" ) );
4.  }
5.}

0