diff --git a/framework/base/src/org/ofbiz/base/util/GroovyUtil.java b/framework/base/src/org/ofbiz/base/util/GroovyUtil.java index 44102f3440..9e3b69a425 100644 --- a/framework/base/src/org/ofbiz/base/util/GroovyUtil.java +++ b/framework/base/src/org/ofbiz/base/util/GroovyUtil.java @@ -47,7 +47,7 @@ public class GroovyUtil { public static GroovyClassLoader groovyClassLoader = new GroovyClassLoader(); - private static Binding getBinding(Map context) { + public static Binding getBinding(Map context) { Binding binding = new Binding(); if (context != null) { Set keySet = context.keySet(); diff --git a/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java b/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java index f41a76ca75..5ec5577d82 100644 --- a/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java +++ b/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java @@ -29,6 +29,7 @@ import java.util.TimeZone; import org.ofbiz.base.util.cache.UtilCache; import org.ofbiz.base.util.*; import org.codehaus.groovy.control.CompilationFailedException; +import org.codehaus.groovy.runtime.InvokerHelper; import bsh.EvalError; @@ -307,13 +308,16 @@ public class FlexibleStringExpander implements Serializable { } protected static class GroovyElem implements StrElem { - protected final String str; + protected final String originalString; + protected final Class parsedScript; protected GroovyElem(String script) { - this.str = script; + this.originalString = script; + this.parsedScript = GroovyUtil.groovyClassLoader.parseClass(script); } public void append(StringBuilder buffer, Map context, TimeZone timeZone, Locale locale) { try { - Object obj = GroovyUtil.eval(this.str, UtilMisc.makeMapWritable(context)); + // this approach will re-parse the script each time: Object obj = GroovyUtil.eval(this.str, UtilMisc.makeMapWritable(context)); + Object obj = InvokerHelper.createScript(this.parsedScript, GroovyUtil.getBinding(context)).run(); if (obj != null) { try { buffer.append(ObjectType.simpleTypeConvert(obj, "String", null, timeZone, locale, true)); @@ -322,11 +326,14 @@ public class FlexibleStringExpander implements Serializable { } } else { if (Debug.verboseOn()) { - Debug.logVerbose("Groovy scriptlet evaluated to null [" + this.str + "], got no return so inserting nothing.", module); + Debug.logVerbose("Groovy scriptlet evaluated to null [" + this.originalString + "], got no return so inserting nothing.", module); } } } catch (CompilationFailedException e) { - Debug.logWarning(e, "Error evaluating Groovy scriptlet [" + this.str + "], inserting nothing; error was: " + e, module); + Debug.logWarning(e, "Error evaluating Groovy scriptlet [" + this.originalString + "], inserting nothing; error was: " + e, module); + } catch (Exception e) { + // handle other things, like the groovy.lang.MissingPropertyException + Debug.logWarning(e, "Error evaluating Groovy scriptlet [" + this.originalString + "], inserting nothing; error was: " + e, module); } } } diff --git a/framework/example/widget/example/FormWidgetExampleForms.xml b/framework/example/widget/example/FormWidgetExampleForms.xml index 3aff3b78ef..81a588d0d8 100644 --- a/framework/example/widget/example/FormWidgetExampleForms.xml +++ b/framework/example/widget/example/FormWidgetExampleForms.xml @@ -39,8 +39,8 @@ under the License. - - + + @@ -108,7 +108,7 @@ under the License. entry-name="exampleDateField" title="${uiLabelMap.ExampleDateField8Title}" tooltip="${uiLabelMap.ExampleDateField8Tooltip}"> - +