You can use the same technique described in http://cwiki.apache.org/WICKET/forms-with-dynamic-elements.html to dynamically add components to a page.

Wicket xhtml tag <wicket:container> comes in handy on these cases. Bellow is a simple example of a page with dynamic components:

MasterPage.java

public class MasterPage extends WebPage
{
	public MasterPage()
	{
		List<Component> components = new ArrayList<Component>();
		components.add( new Component() );
		components.add( new Component() );
		add( new ListView( "components", components )
		{			
			protected void populateItem(ListItem item)
			{
				item.add( (Component)item.getModelObject() );
			}
		});
	}
}

MasterPage.html

<html>
<body>
	<wicket:container wicket:id="components">
		<wicket:container wicket:id="component"/>
	</wicket:container> 
</body>
</html>

Component.java

public class Component extends Panel
{
	public Component()
	{
		super( "component" );
		add( new Label( "name" ), "component 1" );
	}
}

Component.html

<html>
<wicket:panel>
	<span wicket:id="name">component name</span>
</wicket:panel>
</html>
  • No labels