As Eelco mentioned, there are quite a few ways... I typically use delegation
for this sort of thing with a model that wraps another model. This way it
can be reused for a Label, dropdown, textfield, etc....
you could do then:
add(new Label<String>("myLabelID", new UpperCaseModel(new
PropertyModel(myObject, "myField"))));
With code like:
import org.apache.wicket.model.IModel;
public class UpperCaseModel implements IModel<String> {
private static final long serialVersionUID = 1L;
private final IModel<String> mNestedModel;
public UpperCaseModel(IModel<String> nestedModel) {
if (nestedModel == null) {
throw new IllegalArgumentException("parameter 'nestedModel' can
not be 'null'.");
}
mNestedModel = nestedModel;
}
public String getObject() {
String obj = mNestedModel.getObject();
return obj == null ? obj : obj.toUpperCase();;
}
public void setObject(String object) {
mNestedModel.setObject(object);
}
public void detach() {
mNestedModel.detach();
}
}
Hope this helps...
Jeremy Thomerson
On Wed, May 7, 2008 at 4:06 PM, Eelco Hillenius <[EMAIL PROTECTED]>
wrote:
> > I need your suggestion on, what are the ways I can get Label to print
> in
> > Uppercase.
>
> Several ways. An easy one:
>
> public class UpperCaseLabel extends Label {
>
> public UpperCaseLabel(String id) {
> super(id);
> }
>
> public UpperCaseLabel(String id, String label) {
> super(id, label);
> }
>
> public UpperCaseLabel(String id, IModel model) {
> super(id, model);
> }
>
> @Override
> protected void onComponentTagBody(final MarkupStream markupStream,
> final ComponentTag openTag) {
> String s = getModelObjectAsString();
> replaceComponentTagBody(markupStream, openTag, s != null ?
> s.toUpperCase() : null);
> }
> }
>
> Eelco
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>