Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling a controller method with a date using the Play Framework
    primarykey
    data
    text
    <p>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</p> <pre>public static void viewDay( @As("dd-MM-yyyy") Date date) {</pre> <p>Which works fine when accessed via the web at /day?date=22-05-2011 or whatever.</p> <p>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.</p> <p>My initial idea was just to pass the date object along in a <pre>viewDay(someDate);</pre> 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.</p> <p>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.</p> <p>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.</p> <p>Thanks, Carl</p> <p></p> <p>Rough overview of my controller:</p> <pre> public class TimeRecordController extends Controller { public static void index() { //do stuff } public static void viewDay( @As("dd-MM-yyyy") Date date) { //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 viewDay(rtn); } } </pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload