Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

e.g. You have a target myPanel

Code Block
html
html
<span wicket:id="myPanel">Example input (will be removed)</span>

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

Code Block
html
html
<wicket:fragment wicket:id="frag1">panel 1</wicket:fragment>
<wicket:fragment wicket:id="frag2">panel 2</wicket:fragment>

...

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

Advanced Example

In the code below a table is rendered where even and uneven rows have a different color.:

Code Block
html
html

<html>
<head><title>Fragments Test</title></head>
<body>

<table border="1"> 
  <tr>
    <th>id</th>
    <th>Column</th>
  </tr>
  
  <span wicket:id="list">
  
   <span wicket:id="placeholderForFragmentedListItem">[content will go here]</span>
   
	<wicket:fragment wicket:id="variant_even">
	  <tr bgcolor="lightgrey">
		<td wicket:id="rownum">1</td>
		<td >Variant 1</td>
	  </tr>
	</wicket:fragment>
	
	<wicket:fragment wicket:id="variant_uneven">
	  <tr bgcolor="white">
		<td wicket:id="rownum">2</td>
		<td >Variant 2</td>
	  </tr>
	</wicket:fragment>
	
  </span>
</table>

</body>
</html>

and the corosponding Java code:

Code Block

public class FragmentsTest extends WebPage {

  public FragmentsTest() {
    Loop loop = new Loop("list", 5) {
      protected void populateItem(LoopItem item) {

        String fragmentId;
        if (0 == item.getIteration() % 2) {
          fragmentId = "variant_even";
        } else {
          fragmentId = "variant_uneven";
        }

        Fragment frag = new Fragment(
				"placeholderForFragmentedListItem", fragmentId, this);
        frag.add(new Label("rownum", "" + item.getIteration()));
        item.add(frag);
      }
    };
    add(loop);
  }
}

Note

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

Code Block
html
html
<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>