This is an automated email from the ASF dual-hosted git repository.
jamesyong pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git The following commit(s) were added to refs/heads/trunk by this push: new 76a940a Improved: Make locale available for DateFindField and DateTimeField macros (OFBIZ-12086) 76a940a is described below commit 76a940ab43b25a1d77c433e0a8071cbd818fdef0 Author: James Yong <[hidden email]> AuthorDate: Sat Dec 5 23:13:55 2020 +0800 Improved: Make locale available for DateFindField and DateTimeField macros (OFBIZ-12086) DateFindField and DateTimeField macros need to find locale-specific javascript library files. --- .../apache/ofbiz/widget/renderer/macro/FtlWriter.java | 12 +++++++++--- .../ofbiz/widget/renderer/macro/MacroFormRenderer.java | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/FtlWriter.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/FtlWriter.java index cb48600..0be368f 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/FtlWriter.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/FtlWriter.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.io.Reader; import java.io.StringReader; import java.rmi.server.UID; +import java.util.Locale; import java.util.Map; import java.util.WeakHashMap; @@ -45,9 +46,9 @@ public final class FtlWriter { this.visualTheme = visualTheme; } - public void executeMacro(Appendable writer, String macro) { + public void executeMacro(Appendable writer, Locale locale, String macro) { try { - Environment environment = getEnvironment(writer); + Environment environment = getEnvironment(writer, locale); environment.setVariable("visualTheme", FreeMarkerWorker.autoWrap(visualTheme, environment)); environment.setVariable("modelTheme", FreeMarkerWorker.autoWrap(visualTheme.getModelTheme(), environment)); Reader templateReader = new StringReader(macro); @@ -59,13 +60,18 @@ public final class FtlWriter { } } - private Environment getEnvironment(Appendable writer) throws TemplateException, IOException { + private Environment getEnvironment(Appendable writer, Locale locale) throws TemplateException, IOException { Environment environment = environments.get(writer); if (environment == null) { Map<String, Object> input = UtilMisc.toMap("key", null); environment = FreeMarkerWorker.renderTemplate(macroLibrary, input, writer); environments.put(writer, environment); } + if (locale != null) { + environment.setLocale(locale); + } else { + environment.setLocale(Locale.getDefault()); + } return environment; } } diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java index 1ff4731..9fa988e 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java @@ -168,7 +168,17 @@ public final class MacroFormRenderer implements FormStringRenderer { } private void executeMacro(Appendable writer, String macro) { - ftlWriter.executeMacro(writer, macro); + ftlWriter.executeMacro(writer, null, macro); + } + + /** + * Make locale available before executing macro + * @param writer + * @param locale + * @param macro + */ + private void executeMacro(Appendable writer, Locale locale, String macro) { + ftlWriter.executeMacro(writer, locale, macro); } private String encode(String value, ModelFormField modelFormField, Map<String, Object> context) { @@ -789,7 +799,7 @@ public final class MacroFormRenderer implements FormStringRenderer { sr.append("\" disabled="); sr.append(Boolean.toString(disabled)); sr.append(" />"); - executeMacro(writer, sr.toString()); + executeMacro(writer, (Locale) context.get("locale"), sr.toString()); this.addAsterisks(writer, context, modelFormField); this.appendTooltip(writer, context, modelFormField); } @@ -2228,7 +2238,7 @@ public final class MacroFormRenderer implements FormStringRenderer { sr.append("\" tabindex=\""); sr.append(tabindex); sr.append("\" />"); - executeMacro(writer, sr.toString()); + executeMacro(writer, locale, sr.toString()); this.appendTooltip(writer, context, modelFormField); } |
Free forum by Nabble | Edit this page |