Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[#1148] fix(tag): yesno should evaluates NullObject as false

commit 9285dcfbec25097b4a03e1b5b740301ce637b99f 1 parent 72309f4
Alexandre Chatiron xael-fry authored
6 framework/src/play/templates/FastTags.java
View
@@ -15,6 +15,8 @@
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
+import org.codehaus.groovy.runtime.NullObject;
+
import play.cache.Cache;
import play.data.validation.Error;
import play.data.validation.Validation;
@@ -275,7 +277,9 @@ static boolean _evaluateCondition(Object test) {
return ((Number) test).intValue() != 0;
} else if (test instanceof Collection) {
return !((Collection) test).isEmpty();
- } else {
+ } else if (test instanceof NullObject) {
+ return false;
+ } else {
return true;
}
}
5 framework/test-src/play/templates/JavaExtensionsTest.java
View
@@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.codehaus.groovy.runtime.NullObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -214,7 +215,9 @@ public void testYesno() {
assertEquals(no, JavaExtensions.yesno(testCollection, yesNo));
testCollection.add("1");
assertEquals(yes, JavaExtensions.yesno(testCollection, yesNo));
-
+ // NullObject
+ NullObject nullOject = NullObject.getNullObject();
+ assertEquals(no, JavaExtensions.yesno(nullOject, yesNo));
}
@Test
11 samples-and-tests/just-test-cases/app/controllers/tagDemos/TagDemos.java
View
@@ -0,0 +1,11 @@
+package controllers.tagDemos;
+
+import play.mvc.Controller;
+
+public class TagDemos extends Controller {
+
+ public static void yesNo() {
+ render();
+ }
+
+}
5 samples-and-tests/just-test-cases/app/views/tagDemos/TagDemos/yesNo.html
View
@@ -0,0 +1,5 @@
+<ul>
+<li>${nullObjectReference?.someProperty.yesno("yes", "no")}</li>
+
+<li>${"nullObjectReference?.someProperty".yesno("yes")}</li>
+</ul>
3  samples-and-tests/just-test-cases/conf/routes
View
@@ -62,7 +62,8 @@ GET /index2 Application.index2
# Catch all
* /async/{controller}/{action} async.{controller}.{action}
-* /sample/{controller}/{action} sample.{controller}.{action}
+* /sample/{controller}/{action} sample.{controller}.{action}
+* /tagDemos/{controller}/{action} tagDemos.{controller}.{action}
* /{controller}/{action} {controller}.{action}
# Data binding
Please sign in to comment.
Something went wrong with that request. Please try again.