Hi guys,

I had an idea last night and decided to implement it.

On my wicket app I have a lot of labels that is used just to display the
model values to the user.
So my code was some thing like this:

WebMarkupContainer container = new WebMarkupContainer("container", new
new Label("prop1");
new Label("prop2.name");
new Label("prop2.lastname")

html was like this:
<div wicket:id="container">
Prop1: <span wicket:id="prop1"></span>
Prop2 name: <span wicket:id="prop2.name"></span>
Prop2 lastname: <span wicket:id="prop2.lastname"></span>

So I decided to try to simplify the HTML code and created a
TemplateMarkupComponent which basically uses the VariableInterpolator class
and PropertyResolver:

java looks like this:

TemplateMarkupContainer container = new
TemplateMarkupContainer("container", myModel);

Html code:

<div wicket:id="container">
Prop1: ${prop1}
Prop2 name: ${prop2.name}
Prop2 lastname:  ${prop2.lastname}

To display the values the component apply the PropertyConverter, so fields
are displayed with the correct format.
It uses the same expressions that PropertyModel uses to get its properties.
I think this could be used to render scripts as well.

You can just remove the expression tag from HTML without having to change
the java code.
You can choose if and Exception should be raised if the Model doesn't
contains the property, like the MapVariableInterpolator does.

These two I am still thinking about:
You can override the onValue(String expression, Object value) in order to
modify the value that is rendered
If you pass a Model with is not an Object with properties, like just a
String or Int, you can render it by using ${this}

It is just two classes:

Do you think that this could be useful?
What problems could be raised by this approach?


Marcel Barbosa Pinto

Reply via email to