New project wicket-datetime (using the force)

6 02 2007

Those of you following the developer list may already have noticed it, but this weekend I added a new core project to our repository: wicket-datetime.The motivation behind this project is the fact that dealing with the normal date API in the JDK finally drove me insane, and that for the project I’m working on we built a couple of components that depend on a much nicer date API: joda-time.Joda-time is a fantastic example of object oriented craftmanship. I find it’s API elegant and intuitive, and – very important – everything just works like you would expect it to work. That includes working with time zones, which is something I recently had to deal with.Consider this case:We have a system that logs the timestamp when entries of a certain entity were added.dump.pngNow say, I’m working in Seattle, and the server is in Amsterdam. Amsterdam is nine hours ahead of Seattle. If I would be adding an entry on monday evening the 5th of february, the entry would be saved as being added on tuesday the 6th, as that is the date the server would be working in. Hence, even though it is still monday evening for me, my entry would show up in the list as being added on tuesday morning!The right thing to do here is to take the server date as the reference point, and when communicating with users (displaying and taking input), apply the time zone difference. So, in the above example, the server would store tuesday morning as the date that the entry was saved but it would show up in my browser in Seattle as monday evening.There are multiple strategies you can follow of course, like saving dates including time zone information (probably the safest route to follow), providing the client with time zone information and other variants. However, applying the time zone difference like I sketched above seemed like a generic enough solution to me to justify abstracting a few classes.The wicket-datetime project provides a Converter that takes the client’s time zone into account, and it also provides a date text field that works with this converter. Use that converter for your components, and the time zone difference will be applied for you automatically.The project also provides a new calendar/ date picker component, this time based on the Yahoo User Interface library (YUI) calendar widget. The DatePicker we had before was badly written (sorry for that, I hope I did a better job at this one) as it focussed too much on being ‘easily’ configurable. And the fact that it was based on a javascript widget that had quite a few bugs but wasn’t maintained anymore didn’t really help us feel great about the component either. There is a datepicker in the Dojo integration project, and there might be a fresh one (or two, who knows) put in the wicket-extensions project when someone (Al/ Igor/ Matej?) is up to it. But this date picker is well integrated with the other components in the project and relies of joda-time for it’s functioning (though if there is enough intrest that might be factored out).Finally, two more components that the wicket-datetime project provides at this stage are DateField and DateTimeField. The latter is a nice combination of a date text field, date picker, a field for hours and a field for minutes and a AM/PM selection.dump2.pngI plan to work on this component a bit too, so that it depends on the client’s locale whether a 24 hour system or a 12 hour system with AM/ PM is used.I hope people will start playing with the project soon, and I’m eagerly waiting for suggestions and patches and stuff!


Actions

Information

15 responses

9 02 2007
shelbycockrell

Seems like you know a lot. Cool blog!

5 03 2007
dwi ardi irawan

nice component if wicket can do that.
i’m an tapestry user since this past 1 year.
when i hear wicket… i directly interested to try it
what i want to ask : when wicket 2 is going to be released ?
cos it’s been more than 2 months i’m waiting for it.

5 03 2007
10 06 2007
Fredrik

I really like the concept of this component. To me it seems, as a datetime-component would be one of the more essential to create. As I’m creating a site in Swedish I’m looking forward to the 24-hour version.

One question though, is it possible to validate (wicket validate) that one datetimefield has inputted a date after some other datetimefield? I’m thinking something like “you have to make the return trip after the initial trip”.

Thank you for giving us Wicket! Web development is fun again :)

10 06 2007
Eelco Hillenius

Hi Fredrik,

That validation is possible. Until very recently there was a bug that prevented the component to work well with validators, but now it should work like any other. I think you would do a comparing validation with a FormValidator. Good luck, and thanks for the encouragement!

11 07 2007
bhaskar

Hi,
One thing that bothers me, about this component, is that when you have 2 or more DateTimeFields, The pop-up box always appears in the same place , this is really confusing.
It would be better if the pop-up box appeared near the concerned text field.

I think this may be an issue with YUI rather than your component.

keep up the good work.

btw why didn’t you add this to wicket-extenstions, rather than creating a new project ?

11 07 2007
Eelco Hillenius

@bhaskar

Hmmm, you’re right, it sometimes does this. It typically behaved right for me, but I just found a case in my application where it doesn’t. I’ll look into it.

It was put into a separate project because of it’s dependency. We’re trying to keep wicket and wicket-extensions as light as we can when it comes to dependencies. There’s a discussion about in in the mail archives (developer list).

19 07 2007
bhaskar

Hi,
Another feedback, (btw thanks for the earlier response).

The DateTimeField doesn’t work properly with validators.
I added a DateValidator to it, and it works correctly when the input validates,
but when the input is invalid, the datevalidator throws the following exception, instead of adding an error message to the session.
WicketMessage: Exception ‘java.lang.IllegalArgumentException: Value of variable [[input]] could not be resolved while interpolating [['${input}' must be greater than ${minimum}.]]’ occurred during validation org.apache.wicket.validation.validator.DateValidator$MinimumValidator on component 4:dateForm:datetime
Root cause:
java.lang.IllegalArgumentException: Value of variable [[input]] could not be resolved while interpolating [['${input}' must be greater than ${minimum}.]]
at org.apache.wicket.util.string.interpolator.VariableInterpolator.toString(VariableInterpolator.java:117)

19 07 2007
Eelco Hillenius

Hmmm, I fixed a related bug for that not too long ago. Are you using a recent version of Wicket? Anyway, if you find bugs, it would be great if you register them in JIRA.

11 09 2007
A Wicket Diary» Blog Archive » Gerolf Seitz joins the Wicket team!

[...] Wicket team is proud to welcome Gerolf Seitz on board. Gerolf has been working on wicket-datetime, created a really nice wicket-jmx panel for configuring your Wicket application while it is [...]

3 12 2007
JulianS

Note: The URL to this project is now (as of Nov 2007):
http://svn.apache.org/repos/asf/wicket/trunk/jdk-1.4/wicket-datetime/

3 12 2007
Eelco Hillenius

Thanks JulianS. I updated the entry.

8 02 2008
cr00k

Component looks good, I will try it out in my new project!

26 03 2008
aknyazev

hi, I have a problem, when I add two or more datefields it runs very slow on client-side.

26 03 2008
aknyazev

sorry, it runs slow only on internet explorer 6. On 7th version of explorer and other browsers(Opera,Firefox) works good.

Leave a comment