Permalink
Browse files

[#276] [#278] Fix date unbinding

  • Loading branch information...
1 parent 1531d15 commit f64e53ab05bc220a5b22fffc11bf44034e2b895a @guillaumebort guillaumebort committed Oct 17, 2010
@@ -3,10 +3,13 @@
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Date;
import java.util.List;
import java.util.Map;
+import play.data.binding.types.DateBinder;
/**
* Try to unbind an object to a Map<String,String>
@@ -47,6 +50,8 @@ private static void unBind(Map<String, Object> result, Object src, Class<?> srcC
unBind(result, object, object.getClass(), name);
}
}
+ } else if (Date.class.isAssignableFrom(src.getClass())) {
+ result.put(name, src != null ? new SimpleDateFormat(DateBinder.ISO).format((Date)src) : null);
} else {
Field[] fields = src.getClass().getDeclaredFields();
for (Field field : fields) {
@@ -77,6 +77,10 @@ public static void dynamicClassBinding(boolean fail) {
public static void tagContexts() {
render();
}
+
+ public static void book(Date at) {
+ renderText("Booked at %1$tm %1$te,%1$tY !!", at);
+ }
public static void escapeData() {
String oops = "&nbsp;<i>Yop</i>&nbsp;";
@@ -60,4 +60,8 @@
open('@{DataBinding.globalBinder('8')}')
assertTextPresent('Incorrect value')
+ <!-- Now unbind dates -->
+ open('@{Application.book(new java.util.Date(2879877856556))}')
+ assertTextPresent('Booked at 04 5,2061 !!')
+
#{/selenium}

0 comments on commit f64e53a

Please sign in to comment.