Author: jacopoc
Date: Fri Mar 30 07:28:39 2012
New Revision: 1307288
URL: http://svn.apache.org/viewvc?rev=1307288&view=rev
Log:
Implemented new Freemarker transform to set a context variable.
The transform is now used to pass the "postalAddress" to the context of the
postal address formatter screen.
This should fix the issue, reported by Chatree, that prevented to render the localized address when the screen was
rendered from the send mail service (no request object was available).
Added:
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/ftl/SetContextFieldTransform.java
Modified:
ofbiz/trunk/applications/order/webapp/ordermgr/order/companyHeader.fo.ftl
ofbiz/trunk/applications/order/webapp/ordermgr/order/ordercontactinfo.ftl
ofbiz/trunk/applications/order/webapp/ordermgr/quote/quoteReportContactMechs.fo.ftl
ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/GetPostalAddressTemplate.groovy
ofbiz/trunk/applications/party/webapp/partymgr/party/profileblocks/Contact.ftl
ofbiz/trunk/framework/webapp/config/freemarkerTransforms.properties
Modified:
ofbiz/trunk/applications/order/webapp/ordermgr/order/companyHeader.fo.ftl
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/order/companyHeader.fo.ftl?rev=1307288&r1=1307287&r2=1307288&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/webapp/ordermgr/order/companyHeader.fo.ftl
(original)
+++ ofbiz/trunk/applications/order/webapp/ordermgr/order/companyHeader.fo.ftl
Fri Mar 30 07:28:39 2012
@@ -26,7 +26,7 @@ under the License.
<fo:block>${companyName}</fo:block>
<#if postalAddress?exists>
<#if postalAddress?has_content>
- ${setRequestAttribute("postalAddress", postalAddress)}
+ ${setContextField("postalAddress", postalAddress)}
${screens.render("component://party/widget/partymgr/PartyScreens.xml#postalAddressPdfFormatter")}
</#if>
<#else>
Modified:
ofbiz/trunk/applications/order/webapp/ordermgr/order/ordercontactinfo.ftl
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/order/ordercontactinfo.ftl?rev=1307288&r1=1307287&r2=1307288&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/webapp/ordermgr/order/ordercontactinfo.ftl
(original)
+++ ofbiz/trunk/applications/order/webapp/ordermgr/order/ordercontactinfo.ftl
Fri Mar 30 07:28:39 2012
@@ -117,7 +117,7 @@ under the License.
<#assign postalAddress = orderContactMechValueMap.postalAddress>
<#if postalAddress?has_content>
<div>
- ${setRequestAttribute("postalAddress", postalAddress)}
+ ${setContextField("postalAddress", postalAddress)}
${screens.render("component://party/widget/partymgr/PartyScreens.xml#postalAddressHtmlFormatter")}
</div>
<@updateOrderContactMech orderHeader=orderHeader?if_exists
contactMechTypeId=contactMech.contactMechTypeId contactMechList=postalContactMechList?if_exists
contactMechPurposeTypeId=contactMechPurpose.contactMechPurposeTypeId?if_exists
contactMechAddress=postalAddress?if_exists />
Modified:
ofbiz/trunk/applications/order/webapp/ordermgr/quote/quoteReportContactMechs.fo.ftl
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/quote/quoteReportContactMechs.fo.ftl?rev=1307288&r1=1307287&r2=1307288&view=diff
==============================================================================
---
ofbiz/trunk/applications/order/webapp/ordermgr/quote/quoteReportContactMechs.fo.ftl
(original)
+++
ofbiz/trunk/applications/order/webapp/ordermgr/quote/quoteReportContactMechs.fo.ftl
Fri Mar 30 07:28:39 2012
@@ -39,8 +39,8 @@ under the License.
<fo:table-cell>
<fo:block>
<#if toPostalAddress?exists>
- ${setRequestAttribute("postalAddress",
toPostalAddress)}
-
${screens.render("component://party/widget/partymgr/PartyScreens.xml#postalAddressPdfFormatter")}
+ ${setContextField("postalAddress",
toPostalAddress)}
+
${screens.render("component://party/widget/partymgr/PartyScreens.xml#postalAddressPdfFormatter")}
</#if>
</fo:block>
</fo:table-cell>
Modified:
ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/GetPostalAddressTemplate.groovy
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/GetPostalAddressTemplate.groovy?rev=1307288&r1=1307287&r2=1307288&view=diff
==============================================================================
---
ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/GetPostalAddressTemplate.groovy
(original)
+++ ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/GetPostalAddressTemplate.groovy Fri Mar 30
07:28:39 2012
@@ -17,7 +17,7 @@
* under the License.
*/
-postalAddressForTemplate = request.getAttribute("postalAddress");
+postalAddressForTemplate = context.postalAddress;
postalAddressTemplateSuffix = context.postalAddressTemplateSuffix;
if (!postalAddressTemplateSuffix) {
Modified:
ofbiz/trunk/applications/party/webapp/partymgr/party/profileblocks/Contact.ftl
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/webapp/partymgr/party/profileblocks/Contact.ftl?rev=1307288&r1=1307287&r2=1307288&view=diff
==============================================================================
---
ofbiz/trunk/applications/party/webapp/partymgr/party/profileblocks/Contact.ftl
(original)
+++
ofbiz/trunk/applications/party/webapp/partymgr/party/profileblocks/Contact.ftl
Fri Mar 30 07:28:39 2012
@@ -59,7 +59,7 @@ under the License.
<#if "POSTAL_ADDRESS" = contactMech.contactMechTypeId>
<#if contactMechMap.postalAddress?has_content>
<#assign postalAddress = contactMechMap.postalAddress>
- ${setRequestAttribute("postalAddress", postalAddress)}
+ ${setContextField("postalAddress", postalAddress)}
${screens.render("component://party/widget/partymgr/PartyScreens.xml#postalAddressHtmlFormatter")}
<#if postalAddress.geoPointId?has_content>
<#if contactMechPurposeType?has_content>
Modified: ofbiz/trunk/framework/webapp/config/freemarkerTransforms.properties
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/config/freemarkerTransforms.properties?rev=1307288&r1=1307287&r2=1307288&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/config/freemarkerTransforms.properties
(original)
+++ ofbiz/trunk/framework/webapp/config/freemarkerTransforms.properties Fri Mar
30 07:28:39 2012
@@ -27,3 +27,4 @@ ofbizCurrency=org.ofbiz.webapp.ftl.Ofbiz
ofbizAmount=org.ofbiz.webapp.ftl.OfbizAmountTransform
setRequestAttribute=org.ofbiz.webapp.ftl.SetRequestAttributeMethod
renderWrappedText=org.ofbiz.webapp.ftl.RenderWrappedTextTransform
+setContextField=org.ofbiz.webapp.ftl.SetContextFieldTransform
Added:
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/ftl/SetContextFieldTransform.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/ftl/SetContextFieldTransform.java?rev=1307288&view=auto
==============================================================================
---
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/ftl/SetContextFieldTransform.java
(added)
+++
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/ftl/SetContextFieldTransform.java
Fri Mar 30 07:28:39 2012
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
*******************************************************************************/
+package org.ofbiz.webapp.ftl;
+
+import freemarker.core.Environment;
+import freemarker.ext.beans.BeanModel;
+import freemarker.template.*;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * SetRequestAttributeMethod - Freemarker Method for setting context fields
+ */
+public class SetContextFieldTransform implements TemplateMethodModelEx {
+
+ public static final String module =
SetContextFieldTransform.class.getName();
+
+ /*
+ * @see freemarker.template.TemplateMethodModel#exec(java.util.List)
+ */
+ @SuppressWarnings("unchecked")
+ public Object exec(List args) throws TemplateModelException {
+ if (args == null || args.size() != 2)
+ throw new TemplateModelException("Invalid number of arguements");
+ if (!(args.get(0) instanceof TemplateScalarModel))
+ throw new TemplateModelException("First argument not an instance of
TemplateScalarModel");
+ if (!(args.get(1) instanceof BeanModel) && !(args.get(1) instanceof TemplateNumberModel) && !(args.get(1)
instanceof TemplateScalarModel))
+ throw new TemplateModelException("Second argument not an instance of BeanModel nor TemplateNumberModel
nor TemplateScalarModel");
+
+ Environment env = Environment.getCurrentEnvironment();
+ BeanModel req = (BeanModel)env.getVariable("context");
+ Map context = (Map) req.getWrappedObject();
+
+ String name = ((TemplateScalarModel) args.get(0)).getAsString();
+ Object value = null;
+ if (args.get(1) instanceof TemplateScalarModel)
+ value = ((TemplateScalarModel) args.get(1)).getAsString();
+ if (args.get(1) instanceof TemplateNumberModel)
+ value = ((TemplateNumberModel) args.get(1)).getAsNumber();
+ if (args.get(1) instanceof BeanModel)
+ value = ((BeanModel) args.get(1)).getWrappedObject();
+
+ context.put(name, value);
+ return new SimpleScalar("");
+ }
+
+}