Author: rwhitcomb
Date: Fri Apr 22 17:13:47 2016
New Revision: 1740570

URL: http://svn.apache.org/viewvc?rev=1740570&view=rev
Log:
PIVOT-987:  Address the different handling of script return values
from attributes versus elements.

The script return value was being ignored in AttributeInvocationHandler
and the default values were always being used.  But in the similar
code in ElementInvocationHandler the script result was being used
and the defaults only used if the script method returns nothing.

Bring the code for attributes in line with that for elements.


Modified:
    pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java

Modified: pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java?rev=1740570&r1=1740569&r2=1740570&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java Fri Apr 22 
17:13:47 2016
@@ -145,18 +145,20 @@ public class BXMLSerializer implements S
                     bindings.put(ARGUMENTS_KEY, args);
                     scriptEngine.setBindings(bindings, 
ScriptContext.ENGINE_SCOPE);
                     scriptEngine.eval(NASHORN_COMPAT_SCRIPT);
-                    scriptEngine.eval(script);
+                    result = scriptEngine.eval(script);
                 } catch (ScriptException exception) {
                     reportException(exception, script);
                 }
             }
 
             // If the function didn't return a value, return the default
-            Class<?> returnType = method.getReturnType();
-            if (returnType == Vote.class) {
-                result = Vote.APPROVE;
-            } else if (returnType == Boolean.TYPE) {
-                result = Boolean.FALSE;
+            if (result == null) {
+                Class<?> returnType = method.getReturnType();
+                if (returnType == Vote.class) {
+                    result = Vote.APPROVE;
+                } else if (returnType == Boolean.TYPE) {
+                    result = Boolean.FALSE;
+                }
             }
 
             return result;


Reply via email to