You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by kan <ka...@gmail.com> on 2008/11/27 17:56:38 UTC
Set format date "inline"
I have a MyPojo with property java.util.Date someDate
I use CompoundPropertyModel<MyPojo>
Now I add components on my page, like add(new Label("someDate")) and
it automagically uses IConvertor to convert from Date to string.
But in some places of web-site I need print only "27/11/2008", in some
places better will be "2 days ago", in some places "27/11/2008
16:53:34 UTC" and so on.
What is an elegant way to specify a format in particular piece of code?
--
WBR, kan.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Set format date "inline"
Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Thu, 27 Nov 2008, kan wrote:
> I have a MyPojo with property java.util.Date someDate
> I use CompoundPropertyModel<MyPojo>
> Now I add components on my page, like add(new Label("someDate")) and
> it automagically uses IConvertor to convert from Date to string.
> But in some places of web-site I need print only "27/11/2008", in some
> places better will be "2 days ago", in some places "27/11/2008
> 16:53:34 UTC" and so on.
> What is an elegant way to specify a format in particular piece of code?
I'm not sure if it's elegant, but you can do
add(new Label("someDate") {
@Override
public IConverter getConverter(Class type) {
return new FooDateConverter();
}
});
If these cases get repeated a lot, you can make named top-level
subclasses of Label for them. Or a generic custom component
with what you can do
add(new DateLabel("someDate").setDateConverter(new FooDateConverter()));
Best wishes,
Timo
--
Timo Rantalaiho
Reaktor Innovations Oy <URL: http://www.ri.fi/ >
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org