I'm trying to figure out how to implement a decorator tag. Here's what I
mean:

I want:

<wicket:modBox style="1">
  <span wicket:id="modBoxText"></span>
</wicket:modBox>

to render to:

<div class="mod-style-1">
  <span>FOO!</span>
</div>

with nothing more than the usual "add( new Label( "modBoxText", "FOO!" ) )"
in the panel class. Note that this is different than a border since there
is no add() for the decorator. The goal of this is to create reusable ui
elements that can be inserted into markup without requiring any wiring in
the java class. From what I understand, this _should_ be possible.

I tried to do this with an IComponentResolver by creating an instance of a
border, but I quickly ran into trouble with the component hierarchy when I
did this and tried to add components to the content of the decorator (such
as <span wicket:id="modBoxText"></span>). Here are the artifacts for this
to get an idea:

ModBoxBorderResolver.java
public class ModBoxBorderResolver implements IComponentResolver {
@Override
public Component resolve( MarkupContainer container, MarkupStream
markupStream, ComponentTag tag ) {

if( tag instanceof WicketTag ) {
 String tagName = tag.getName();
 if( tag.getName().equalsIgnoreCase( "modBox" ) ) {
return ModBoxBorder( "modBox" );
}
}
 return null;
}
}

ModBoxBorder.java
public class ModBoxBorder extends Border {
...
}

ModBoxBorder.html
<wicket:border xmlns:wicket="http://wicket.apache.org";>
<div wicket:id="div" class="${mod-style}">
<wicket:body />
</div>
</wicket:border>

I also notice BorderBehavior whihc might be another avenue, but I'm not
sure exactly how I could get this to work simply by adding tags to the
markup and an IComponentResolver.

Has anyone done anything like this already? Perhaps there is something
already in Wicket that I'm overlooking.

Reply via email to