Is it possible to implement some kind of decorator component in wicket ? Specially while honoring the id of the decorated component ?
Currently i try to solve this using a Border Component acting as a decorator:
Given:
public XXXPage()
{
MyBorder border = new MyBorder("xxx");
border.add( new Label("xxx", "Foo") ); // label just as simplification. Its really a Component that we want to surround the anchor (linkify) around.
add(border);
}
XXXPage.html
<body>
<span wicket:id="xxx"/>
</body>
MyBorder.html
<wicket:border>
<a wicket:id="link"><wicket:body/></a>
</wicket:border>
MyBorder.java
public MyBorder(String id)
{
super(id);
AjaxLink link = new AjaxLink("link")
{
@Override public void onClick(AjaxRequestTarget arg0)
{
}
};
add(link);
link.add(getBodyContainer()); // from javadoc of Wicket's Border
}
Gives:
org.apache.wicket.WicketRuntimeException: The component(s) below failed to render. A common problem is that you have added a component in code but forgot to reference it in the markup (thus the component will never be rendered).
1. [Component id = xxx]
at org.apache.wicket.Page.checkRendering(Page.java:1182)
So in essence, the xxx component should be wrapped in a transparent manner with a link component. This xxx is out of control.
In a "banana wicket" implementation this would be a possible pseudo code:
Component wrapWithAction(Component a) {
// now wrap
Link b = new Link() {
// handle link onClick and all that
}
b.wrap(a);
return b;
}
//