Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: samcday/grails-binders
base: ae9b3c55cc
...
head fork: samcday/grails-binders
compare: 075ac0240a
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
View
6 BindersGrailsPlugin.groovy
@@ -1,5 +1,5 @@
-import au.com.samcday.BinderArtefactHandler
-import au.com.samcday.CustomPropertyEditorRegistrar
+import au.com.samcday.grails.plugins.binders.BinderArtefactHandler
+import au.com.samcday.grails.plugins.binders.CustomPropertyEditorRegistrar
class BindersGrailsPlugin {
// the plugin version
@@ -40,8 +40,6 @@ Custom data binding made easy.
// Online location of the plugin's browseable source code.
// def scm = [ url: "http://svn.grails-plugins.codehaus.org/browse/grails-plugins/" ]
- //def artefacts = [new ConstraintArtefactHandler()]
-
def watchedResources = [
"file:./grails-app/utils/*Binder.groovy"
]
View
15 grails-app/utils/test/StandardFooBinder.groovy
@@ -0,0 +1,15 @@
+package test
+
+class StandardFooBinder {
+ static type = CustomFoo
+
+ def bind = {
+ def (a, b) = [it.split("\\|")]
+
+ return new CustomFoo(a: b, b: b)
+ }
+
+ def asText = {
+ return "${it.a}|${it.b}"
+ }
+}
View
12 .../com/samcday/CustomPropertyEditorRegistrar.groovy → ...gins/binders/CustomPropertyEditorRegistrar.groovy
@@ -1,4 +1,4 @@
-package au.com.samcday
+package au.com.samcday.grails.plugins.binders
import org.springframework.beans.PropertyEditorRegistrar
import org.springframework.beans.PropertyEditorRegistry
@@ -6,14 +6,14 @@ import org.springframework.beans.PropertyEditorRegistry
class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
def grailsApplication
- public CustomPropertyEditorRegistrar() {
- }
-
@Override
void registerCustomEditors(PropertyEditorRegistry propertyEditorRegistry) {
grailsApplication.binderClasses.each {
- println "registering custom handler for ${it.type}"
- propertyEditorRegistry.registerCustomEditor(it.type, new CustomPropertyEditor(binderClass: it))
+ Class type = it.type
+
+ if(type != null) {
+ propertyEditorRegistry.registerCustomEditor(it.type, new CustomPropertyEditor(binderClass: it))
+ }
}
}
}
View
6 src/groovy/test/CustomFoo.groovy
@@ -0,0 +1,6 @@
+package test
+
+class CustomFoo {
+ String a
+ String b
+}
View
2  src/java/au/com/samcday/BinderArtefactHandler.java → ...grails/plugins/binders/BinderArtefactHandler.java
@@ -1,4 +1,4 @@
-package au.com.samcday;
+package au.com.samcday.grails.plugins.binders;
import org.codehaus.groovy.grails.commons.ArtefactHandlerAdapter;
View
2  src/java/au/com/samcday/CustomPropertyEditor.java → .../grails/plugins/binders/CustomPropertyEditor.java
@@ -1,4 +1,4 @@
-package au.com.samcday;
+package au.com.samcday.grails.plugins.binders;
import java.beans.PropertyEditorSupport;
View
13 ...java/au/com/samcday/DefaultGrailsBinderClass.java → ...ils/plugins/binders/DefaultGrailsBinderClass.java
@@ -1,4 +1,4 @@
-package au.com.samcday;
+package au.com.samcday.grails.plugins.binders;
import groovy.lang.Closure;
import org.codehaus.groovy.grails.commons.AbstractInjectableGrailsClass;
@@ -11,8 +11,6 @@
public DefaultGrailsBinderClass(Class clazz) {
super(clazz, BinderArtefactHandler.TYPE);
-
- System.out.println("created binder class ${clazz}");
}
@Override
@@ -32,9 +30,14 @@ public Object bind(String text) {
public String asText(Object val) {
Closure c = (Closure)getPropertyOrStaticPropertyOrFieldValue(AS_TEXT_CLOSURE, Closure.class);
if(c != null) {
- return (String)c.call(val);
+ Object result = c.call(val);
+
+ if(result != null) {
+ return result.toString();
+ }
}
- return val.toString();
+ // Fallback is to just call .toString() on the value, or null if value is null.
+ return val != null ? val.toString() : null;
}
}
View
2  src/java/au/com/samcday/GrailsBinderClass.java → ...day/grails/plugins/binders/GrailsBinderClass.java
@@ -1,4 +1,4 @@
-package au.com.samcday;
+package au.com.samcday.grails.plugins.binders;
import org.codehaus.groovy.grails.commons.InjectableGrailsClass;
View
10 test/integration/au/com/samcday/grails/plugins/binders/BinderTests.groovy
@@ -0,0 +1,10 @@
+package au.com.samcday.grails.plugins.binders;
+
+import org.junit.Test;
+
+public class BinderTests {
+ @Test
+ void testRegularBinding() {
+
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.