THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Code Block |
---|
public class NestedLinkPanel extends Panel { {panel} public NestedLinkPanel(String name, IModel model) { super(name, model); add(new ExternalLink("myLink", "http://google.com").add(new {panel} Label("label", "bar"))); {panel} add(new Label("foo", "Hello, World!")); } {panel} } |
NestedLinkPanel.html:
Code Block | ||||
---|---|---|---|---|
| ||||
<html>
<body>
<wicket:panel>
<a href="#" wicket:id="myLink"><span wicket:id="label">bar</span></a>
<span wicket:id="foo">message goes here</a>
</wicket:panel>
</body>
</html>
|
NestedStaticTextPanel.java:
Code Block |
---|
public class NestedStaticTextPanel extends Panel { {panel} public NestedStaticTextPanel(String name, IModel model) { super(name, model); add(new Label("label", "bar")); add(new Label("foo", "Hello, World!")); } {panel} } |
NestedStaticTextPanel.html:
Code Block | ||||
---|---|---|---|---|
| ||||
<html>
<body>
<wicket:panel>
<span wicket:id="label">bar</span>
<span wicket:id="foo">message goes here</a>
</wicket:panel>
</body>
</html>
|
MyPage.html
Code Block |
---|
<html> <body> <span wicket:id="dynamic">x</span> </body> </html> |
...
Code Block |
---|
public class MyPage extends WebPage { {panel} public MyPage() { Object myModel = // ... if(modelObject instanceof List) { panel = new NestedStaticTextPanel("row", null); } else { panel = new NestedLinkPanel("row", model); } item.add(panel); } {panel} } |
Another approach is to add all components you might want to display, and make all invisible but the one you want to show. This usually takes less code, but it is also much less flexible and not suited for cases where you have a lot of possible components or creating the components is expensive.
...