Skip to content

Commit

Permalink
[#276] [#278] Fix date unbinding
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumebort committed Oct 17, 2010
1 parent 1531d15 commit f64e53a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions framework/src/play/data/binding/Unbinder.java
Expand Up @@ -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>
Expand Down Expand Up @@ -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) {
Expand Down
Expand Up @@ -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;";
Expand Down
4 changes: 4 additions & 0 deletions samples-and-tests/just-test-cases/test/binding.test.html
Expand Up @@ -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.