You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Fragments are effectively in-line panels, i.e. they provide
a way to maintain a panel's piece of markup within the parent's
markup file.

They're just there to help with the cases where you don't
need to share the panel contents between different pages
but are just using them on a single page. In other words,
they're a convinience feature for people to embed repeating
but non-reusable pieces of markup into the parent's markup
file.

Example

e.g. You have a target myPanel

{panel}
  <span wicket:id="myPanel">Example input (will be removed)</span>
{panel}

and in the same markup file you have some fragments, i.e.

{panel}
  <wicket:fragment wicket:id="frag1">panel 1</wicket:fragment>
  <wicket:fragment wicket:id="frag2">panel 2</wicket:fragment>
{panel}

Then at run-time, in your page code, you can decide which to use, e.g.

{panel}
  add(new Fragment("myPanel", "frag1");
{panel}

which will result in the markup from frag 1 being rendered,
i.e. panel 1

Note

If the component that you are putting the fragment in is a subclass, the fragement's markup must be inside the <wicket:extend></wicket:extend> tag:

{panel}
  <wicket:extend>
    ...
    <span wicket:id="myPanel">Example input (will be removed)</span>
    ...
    <wicket:fragment wicket:id="frag1">panel 1</wicket:fragment>
    <wicket:fragment wicket:id="frag2">panel 2</wicket:fragment>
  </wicket:extend>
{panel}
  • No labels