Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix an issue when play try to bind an Siena model, and throw a NullPo…

…interException.

It happens when the model is a parameter of a controller method and when any parameters are given for this object in the HTTP request.
  • Loading branch information...
commit 77bb40640134329f9605b219feb194fb2fe3e564 1 parent 0b8021c
@dwursteisen dwursteisen authored
View
6 build.xml
@@ -15,6 +15,12 @@
</fileset>
</path>
+ <target name="install" depends="build">
+ <!-- urg ! The version shoudn't be hardcoded here, you know... -->
+ <copy todir="${play.path}/modules/siena-2.0.6/lib"
+ file="lib/play-siena.jar" overwrite="true"/>
+ </target>
+
<target name="build" depends="compile">
<copy todir="tmp/classes">
View
15 samples-and-tests/sienatest/app/controllers/Binding.java
@@ -0,0 +1,15 @@
+package controllers;
+
+import models.UUIDModel;
+import play.mvc.Controller;
+
+/**
+ * User: Wursteisen David
+ * Date: 17/12/11
+ * Time: 17:21
+ */
+public class Binding extends Controller {
+ public static void bindMe(UUIDModel myModel) {
+ renderTemplate("Application/index.html");
+ }
+}
View
2  samples-and-tests/sienatest/conf/dependencies.yml
@@ -1,6 +1,6 @@
# Application dependencies
require:
- - play -> play 1.2.3
+ - play -> play [1.2.3,)
- play -> siena [2.0.6,)
- play -> gae 1.6.0_b1
View
24 samples-and-tests/sienatest/test/functional/BindingTest.java
@@ -0,0 +1,24 @@
+package functional;
+
+import org.junit.Test;
+import play.mvc.Http;
+import play.test.FunctionalTest;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * User: Wursteisen David
+ * Date: 17/12/11
+ * Time: 17:25
+ */
+public class BindingTest extends FunctionalTest {
+
+ @Test
+ public void testBindingObjectNotIncludedIntoTheRequest() {
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put("fakeParameters", "fakeValue");
+ Http.Response response = POST("/Binding/bindMe", parameters);
+ assertIsOk(response);
+ }
+}
View
9 src/play/modules/siena/SienaModelUtils.java
@@ -22,6 +22,7 @@
import play.Play;
import play.data.binding.BeanWrapper;
import play.data.binding.Binder;
+import play.data.binding.RootParamNode;
import play.data.validation.Validation;
import play.db.Model;
import play.db.Model.Property;
@@ -286,8 +287,14 @@ else if(isJson){
// v1.0.x code
// bw.bind(name, o.getClass(), params, "", o);
+ RootParamNode paramNode = RootParamNode.convert(params);
+ // no http params to bind this object ? so we won't try to bind this object
+ if(paramNode.getChild(name) == null) {
+ return null;
+ }
// v1.1 compliant
- bw.bind(name, (Type)o.getClass(), params, "", o, o.getClass().getAnnotations());
+
+ bw.bind(name, (Type)o.getClass(), params, "", o, o.getClass().getAnnotations());
return (T) o;
} catch (Exception e) {
Please sign in to comment.
Something went wrong with that request. Please try again.