Versions Compared

Key

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

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

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

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

Component.java

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

Component.html

Code Block
html
html
<html>
<wicket:panel>
	<span wicket:id="name">component name</span>
</wicket:panel>
</html>