Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Excerpt
hiddentrue

How to create consistent layout using Markup Inheritance

Definition

Markup Inheritance lets a Component extend the markup of it's super class. The subclass markup is inserted at one point in the super class markup.

...

You can now combine Markup Inheritance with Header Contribution. First, define a base Page. The markup:

Code Block
html
html
<html>
{panel}
  <head>
  </head>
  <body>
    Base Page Before
    <wicket:child/>
    Base Page After
  </body>
{panel}
</html>

The Java code:

Code Block
class Parent extends Webpage
{
{panel}
  public Parent()
  {
  }
{panel}
}

Next define a child Page. First the markup:

Code Block
<head>
{panel}
  <span wicket:id="label"/>
{panel}
</head>
<wicket:extend>
{panel}
  Child Page
{panel}
</wicket:extend>

The Java code:

Code Block
public class Child extends Parent
{
{panel}
  public Child()
  {
     add(new Label("label", "Here you go"));
  }
{panel}
}

Now, when you fire this all out the resulting page should render as:

Code Block
<html>
{panel}
  <head>
    <span wicket:id="label">Here you go</span>
  </head>
  <body>
    Base Page Before
    Child Page
    Base Page After
  </body>
{panel}
</html>

Markup Inheritance with Wicket 1.1 on Phil's Weblog

...