Take the 2-minute tour ×

This is possibly a stupid question (I'm a bit of a Play Framework noob) but I'm really having no luck with it, essentially I have a display method along the lines of

public static void viewDay( @As("dd-MM-yyyy") Date date) {

Which works fine when accessed via the web at /day?date=22-05-2011 or whatever.

My problem is that I want my save method to redirect back to this page when a new record has been added. In normal circumstances this kinda thing works fine, but since I want to pass a date here I'm running in to some trouble.

My initial idea was just to pass the date object along in a

kinda way(as i've been able to do with other DataTypes) This results in something along the lines of "ISO8601%3A2011-06-30T00%3A00%3A00%2B0100" ending up in the URL. I could live with this if it worked (even though its not ideal), but play doesn't seem to be able to decipher it ether and is just defaulting to using the current date instead.

I've also attempted to pass the date as a String formatted in the way @As expects, though this just resulted in some Type errors. Removing the @As("dd-MM-yyyy") also doesn't appear to help.

To my mind this seems like something that really shouldn't be very hard to do (though as i said I'm a complete noob to Play and Java Web Frameworks in general) so any pointers would be a great help.

Thanks, Carl

Rough overview of my controller:

public class TimeRecordController extends Controller {
    public static void index() {
        //do stuff
        //Do stuff (works fine when accessed via web) 
        //If page is arraived at via the save though url shows UTC date: "ISO8601%3A2011-06-30T00%3A00%3A00%2B0100" 
        //And play is unable to read the correct date
    public static void save(Stuff here, Date rtn){
        //do validation/saving
share|improve this question
The issue is in the code you are not showing, we need the full code of both methods –  Pere Villega Jun 29 '11 at 16:21
add comment

2 Answers

Just call your template with render(date) or call another controller method that expects a Date with your date object. Don't convert the Date to String in your Java code, play handles that automatically during parameter binding. If you need to render your Date object in a certain format in your view templates, you can either make a global setting in the application.conf (scan for "date.format") or render your Date in the template using ${date.format('yyyy-MM-dd')}.

If this does not answer your question, please post your controller code, so that we get a better picture of what you want to achieve.

share|improve this answer
Hello, thanks for getting back to me :) I've added a very rough outline of the controller up top. Basically a form on a viewDay page submits to save(), save does its save-y stuff then calls viewDay() with a date object to show the page again once its complete. The problem is when the date gets passed in this way, so far as I can tell, Play seems unable to read it and thus reverts to using the current date instead of the one passed. Thanks again –  Carl Jun 29 '11 at 10:48
add comment

Is it java util Date or joda date.

The date which is returned is in ISO8601 format. Play uses joda-time which defaults to ISO 8601 calendar system.

share|improve this answer
add comment

Your Answer


