yeah, you pretty much nailed it. although i would extend webmarkupcomponent instead of label since you are really not using any of label's functionality.

as an alternative to this method you can create an imodel decorator that has the formatting in getobject...

IModel.getObject(Component c) {
   Date d=(Datre)delegate.getObject(c);
   return formattedDate(d);
}

that way you can use any existing output component and still maintain the format.

in the project i work on i have the model and the component wraps whatever it gets passed through the consturctor with that model

ie...

class DateLabel extends Label {
    public DateLabel(String id, IModel model) {
          super(id, new DateFormatModel(model));
    }
}

but in the end, whatever works for you :)

-Igor



On 6/21/06, Stefan Arentz <[EMAIL PROTECTED]> wrote:
I keep asking silly questions :-)

I have a lot of ListViews that need to show ISO formatted dates. Is it common practice to make a WebComponent for that? For example like this:

public class DateLabel extends Label
{
    static private final Format sDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public DateLabel(String id)
    {
        super(id);
    }

    public DateLabel(String id, Date model)
    {
        super(id, new Model(model));
    }

    public DateLabel(String id, IModel model)
    {
        super(id, model);
    }

    protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag)
    {
        replaceComponentTagBody(markupStream, openTag, sDateFormat.format(getModelObject()));
    }
}

I must admit that I'm not really in a Wicket Mindset yet. Maybe a Wicket Jedi Master can tell me whether this is the right approach :-)

 S.




_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user



_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to