svn commit: r754626 - in /ofbiz/trunk: applications/product/webapp/catalog/WEB-INF/ applications/product/webapp/catalog/product/ framework/widget/dtd/ framework/widget/src/org/ofbiz/widget/ framework/widget/src/org/ofbiz/widget/form/ framework/widget/s...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r754626 - in /ofbiz/trunk: applications/product/webapp/catalog/WEB-INF/ applications/product/webapp/catalog/product/ framework/widget/dtd/ framework/widget/src/org/ofbiz/widget/ framework/widget/src/org/ofbiz/widget/form/ framework/widget/s...

jonesde
Author: jonesde
Date: Sun Mar 15 07:41:31 2009
New Revision: 754626

URL: http://svn.apache.org/viewvc?rev=754626&view=rev
Log:
Enhanced Form Widget hyperlink type field to support a link-type of hidden-form and to be able to put parameters in a sub-element with name/value (or from-field) pairs; used the EditProductPrices page in the catalog manager as a test case, especially for the Delete ProductPrice links; also improved the URLs there with request-redirect; this is part of the effort to make things generally more secure as parameters are passed in the body and under https will be encrypted; note that this doesn't support multi type forms yet

Modified:
    ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml
    ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml
    ofbiz/trunk/framework/widget/dtd/widget-form.xsd
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java

Modified: ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml?rev=754626&r1=754625&r2=754626&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml Sun Mar 15 07:41:31 2009
@@ -537,19 +537,19 @@
     <request-map uri="createProductPrice">
         <security https="true" auth="true"/>
         <event type="service" path="" invoke="createProductPrice"/>
-        <response name="success" type="view" value="EditProductPrices"/>
+        <response name="success" type="request-redirect" value="EditProductPrices"><redirect-parameter name="productId"/></response>
         <response name="error" type="view" value="EditProductPrices"/>
     </request-map>
     <request-map uri="updateProductPrice">
         <security https="true" auth="true"/>
         <event type="service" path="" invoke="updateProductPrice"/>
-        <response name="success" type="view" value="EditProductPrices"/>
+        <response name="success" type="request-redirect" value="EditProductPrices"><redirect-parameter name="productId"/></response>
         <response name="error" type="view" value="EditProductPrices"/>
     </request-map>
     <request-map uri="deleteProductPrice">
         <security https="true" auth="true"/>
         <event type="service" path="" invoke="deleteProductPrice"/>
-        <response name="success" type="view" value="EditProductPrices"/>
+        <response name="success" type="request-redirect" value="EditProductPrices"><redirect-parameter name="productId"/></response>
         <response name="error" type="view" value="EditProductPrices"/>
     </request-map>
   <!-- ================ Category Content Requests ================= -->

Modified: ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml?rev=754626&r1=754625&r2=754626&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/product/ProductForms.xml Sun Mar 15 07:41:31 2009
@@ -419,8 +419,14 @@
 
         <field name="submitButton" title="${uiLabelMap.CommonUpdate}"><submit button-type="button"/></field>
         <field name="deleteLink" title=" " widget-style="buttontext">
-            <hyperlink target="deleteProductPrice?productId=${productId}&amp;productPriceTypeId=${productPriceTypeId}&amp;productPricePurposeId=${productPricePurposeId}&amp;currencyUomId=${currencyUomId}&amp;productStoreGroupId=${productStoreGroupId}&amp;fromDate=${fromDate}"
-                description="${uiLabelMap.CommonDelete}" also-hidden="false"/>
+            <hyperlink target="deleteProductPrice" description="${uiLabelMap.CommonDelete}" link-type="hidden-form" also-hidden="false">
+                <parameter param-name="productId" from-field="productId"/>
+                <parameter param-name="productPriceTypeId" from-field="productPriceTypeId"/>
+                <parameter param-name="productPricePurposeId" from-field="productPricePurposeId"/>
+                <parameter param-name="currencyUomId" from-field="currencyUomId"/>
+                <parameter param-name="productStoreGroupId" from-field="productStoreGroupId"/>
+                <parameter param-name="fromDate" from-field="fromDate"/>
+            </hyperlink>
         </field>
     </form>
 

Modified: ofbiz/trunk/framework/widget/dtd/widget-form.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-form.xsd?rev=754626&r1=754625&r2=754626&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original)
+++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Sun Mar 15 07:41:31 2009
@@ -44,7 +44,7 @@
         </xs:complexType>
     </xs:element>
     <xs:attributeGroup name="attlist.form">
-        <xs:attribute type="xs:string" name="name" use="required"/>
+        <xs:attribute name="name" type="xs:string" use="required"/>
         <xs:attribute name="type">
             <xs:annotation><xs:documentation>The form type is always required unless you are extending another form.</xs:documentation></xs:annotation>
             <xs:simpleType>
@@ -63,8 +63,8 @@
                 </xs:restriction>
             </xs:simpleType>
         </xs:attribute>
-        <xs:attribute type="xs:string" name="target"/>
-        <xs:attribute type="xs:string" name="target-window"/>
+        <xs:attribute name="target" type="xs:string"/>
+        <xs:attribute name="target-window" type="xs:string"/>
         <xs:attribute name="target-type" default="intra-app">
             <xs:simpleType>
                 <xs:restriction base="xs:token">
@@ -75,15 +75,15 @@
                 </xs:restriction>
             </xs:simpleType>
         </xs:attribute>
-        <xs:attribute type="xs:string" name="id"/>
-        <xs:attribute type="xs:string" name="style"/>
-        <xs:attribute type="xs:string" name="focus-field-name"/>
-        <xs:attribute type="xs:string" name="title"/>
-        <xs:attribute type="xs:string" name="tooltip"/>
-        <xs:attribute type="xs:string" name="list-name">
+        <xs:attribute name="id" type="xs:string"/>
+        <xs:attribute name="style" type="xs:string"/>
+        <xs:attribute name="focus-field-name" type="xs:string"/>
+        <xs:attribute name="title" type="xs:string"/>
+        <xs:attribute name="tooltip" type="xs:string"/>
+        <xs:attribute name="list-name" type="xs:string">
             <xs:annotation><xs:documentation>for list type and other multiple data/form types this is the name of the list in the context to iterate over</xs:documentation></xs:annotation>
         </xs:attribute>
-        <xs:attribute type="xs:string" name="list-entry-name">
+        <xs:attribute name="list-entry-name" type="xs:string">
             <xs:annotation><xs:documentation>if specified each list entry will be put in the context with this name; otherwise the list entry must be a Map and the entries in the Map will be put into the context by name</xs:documentation></xs:annotation>
         </xs:attribute>
         <!-- this is now deprecated, never made sense to separate anyway; use list-name instead <xs:attribute type="xs:string" name="list-iterator-name"/> -->
@@ -231,9 +231,9 @@
         </xs:complexType>
     </xs:element>
     <xs:attributeGroup name="attlist.alt-target">
-        <xs:attribute type="xs:string" name="use-when" use="required"/>
-        <xs:attribute type="xs:string" name="target"/>
-        <xs:attribute type="xs:string" name="target-type"/>
+        <xs:attribute name="use-when" type="xs:string" use="required"/>
+        <xs:attribute name="target" type="xs:string"/>
+        <xs:attribute name="target-type" type="xs:string"/>
     </xs:attributeGroup>
     <xs:element name="alt-row-style">
         <xs:annotation><xs:documentation>Active a style on a line if the use-when condition is validate</xs:documentation></xs:annotation>            
@@ -242,10 +242,10 @@
         </xs:complexType>
     </xs:element>
     <xs:attributeGroup name="attlist.alt-row-style">
-        <xs:attribute type="xs:string" name="use-when" use="required">
+        <xs:attribute name="use-when" type="xs:string" use="required">
             <xs:annotation><xs:documentation>Boolean expression tested for active the style on a line.</xs:documentation></xs:annotation>
         </xs:attribute>
-        <xs:attribute type="xs:string" name="style" use="required">
+        <xs:attribute name="style" type="xs:string" use="required">
             <xs:annotation><xs:documentation>If use-when return true, concat this style to existing style of the line.</xs:documentation></xs:annotation>
         </xs:attribute>
     </xs:attributeGroup>
@@ -255,8 +255,8 @@
         </xs:complexType>
     </xs:element>
     <xs:attributeGroup name="attlist.auto-fields-service">
-        <xs:attribute type="xs:string" name="service-name" use="required"/>
-        <xs:attribute type="xs:string" name="map-name"/>
+        <xs:attribute name="service-name" type="xs:string" use="required"/>
+        <xs:attribute name="map-name" type="xs:string"/>
         <xs:attribute name="default-field-type" default="edit">
             <xs:simpleType>
                 <xs:restriction base="xs:token">
@@ -267,7 +267,7 @@
                 </xs:restriction>
             </xs:simpleType>
         </xs:attribute>
-        <xs:attribute type="xs:positiveInteger" name="default-position" default="1"/>
+        <xs:attribute name="default-position" type="xs:positiveInteger" default="1"/>
     </xs:attributeGroup>
     <xs:element name="auto-fields-entity">
         <xs:complexType>
@@ -275,8 +275,8 @@
         </xs:complexType>
     </xs:element>
     <xs:attributeGroup name="attlist.auto-fields-entity">
-        <xs:attribute type="xs:string" name="entity-name" use="required"/>
-        <xs:attribute type="xs:string" name="map-name"/>
+        <xs:attribute name="entity-name" type="xs:string" use="required"/>
+        <xs:attribute name="map-name" type="xs:string"/>
         <xs:attribute name="default-field-type" default="edit">
             <xs:simpleType>
                 <xs:restriction base="xs:token">
@@ -353,7 +353,7 @@
         </xs:complexType>
     </xs:element>
     <xs:attributeGroup name="attlist.sort-field">
-        <xs:attribute type="xs:string" name="name" use="required"/>
+        <xs:attribute name="name" type="xs:string" use="required"/>
     </xs:attributeGroup>
     <!-- ================== Form Events ==================== -->
     <xs:attributeGroup name="attlist.on-form-event-update-area">
@@ -365,8 +365,8 @@
                 </xs:restriction>
             </xs:simpleType>
         </xs:attribute>
-        <xs:attribute type="xs:string" name="area-id" use="required"/>
-        <xs:attribute type="xs:string" name="area-target" use="required"/>
+        <xs:attribute name="area-id" type="xs:string" use="required"/>
+        <xs:attribute name="area-target" type="xs:string" use="required"/>
     </xs:attributeGroup>
     <xs:element name="on-event-update-area">
         <xs:annotation>
@@ -782,6 +782,9 @@
     </xs:attributeGroup>
     <xs:element name="hyperlink" substitutionGroup="AllFields">
         <xs:complexType>
+            <xs:sequence>
+                <xs:element minOccurs="0" maxOccurs="unbounded" ref="parameter"/>
+            </xs:sequence>
             <xs:attributeGroup ref="attlist.hyperlink"/>
         </xs:complexType>
     </xs:element>
@@ -795,6 +798,14 @@
                 </xs:restriction>
             </xs:simpleType>
         </xs:attribute>
+        <xs:attribute name="link-type" default="anchor">
+            <xs:simpleType>
+                <xs:restriction base="xs:token">
+                    <xs:enumeration value="anchor"/>
+                    <xs:enumeration value="hidden-form"/>
+                </xs:restriction>
+            </xs:simpleType>
+        </xs:attribute>
         <xs:attribute name="target-type" default="intra-app">
             <xs:simpleType>
                 <xs:restriction base="xs:token">
@@ -814,6 +825,16 @@
         <xs:attribute type="xs:string" name="target-window"/>
         <xs:attribute type="xs:string" name="image-location"/>
     </xs:attributeGroup>
+    <xs:element name="parameter">
+        <xs:complexType>
+            <xs:attributeGroup ref="attlist.parameter"/>
+        </xs:complexType>
+    </xs:element>
+    <xs:attributeGroup name="attlist.parameter">
+        <xs:attribute type="xs:string" name="param-name" use="required"/>
+        <xs:attribute type="xs:string" name="from-field"/>
+        <xs:attribute type="xs:string" name="value"/>
+    </xs:attributeGroup>
     <xs:element name="ignored" substitutionGroup="AllFields">
         <xs:complexType/>
     </xs:element>

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java?rev=754626&r1=754625&r2=754626&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java Sun Mar 15 07:41:31 2009
@@ -19,16 +19,21 @@
 package org.ofbiz.widget;
 
 import java.io.IOException;
+import java.io.StringWriter;
+import java.util.List;
 import java.util.Map;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.ofbiz.base.util.StringUtil;
 import org.ofbiz.base.util.UtilHttp;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.webapp.control.RequestHandler;
 import org.ofbiz.webapp.taglib.ContentUrlTag;
+import org.ofbiz.widget.form.ModelForm;
+import org.ofbiz.widget.form.ModelFormField;
 
 public class WidgetWorker {
 
@@ -36,32 +41,60 @@
 
     public WidgetWorker () {}
 
-    public static void buildHyperlinkUrl(Appendable writer, String requestName, String targetType, HttpServletRequest request, HttpServletResponse response, Map<String, Object> context) throws IOException {
-        String localRequestName = UtilHttp.encodeAmpersands(requestName);
+    public static void buildHyperlinkUrl(Appendable externalWriter, String target, String targetType, List<ModelFormField.Parameter> parameterList, HttpServletRequest request, HttpServletResponse response, Map<String, Object> context) throws IOException {
+        String localRequestName = UtilHttp.encodeAmpersands(target);
+        Appendable localWriter = new StringWriter();
         
         if ("intra-app".equals(targetType)) {
-            appendOfbizUrl(writer, "/" + localRequestName, request, response);
+            appendOfbizUrl(localWriter, "/" + localRequestName, request, response);
         } else if ("inter-app".equals(targetType)) {
             String fullTarget = localRequestName;
-            writer.append(fullTarget);
+            localWriter.append(fullTarget);
             String externalLoginKey = (String) request.getAttribute("externalLoginKey");
             if (UtilValidate.isNotEmpty(externalLoginKey)) {
                 if (fullTarget.indexOf('?') == -1) {
-                    writer.append('?');
+                    localWriter.append('?');
                 } else {
-                    writer.append("&amp;");
+                    localWriter.append("&amp;");
                 }
-                writer.append("externalLoginKey=");
-                writer.append(externalLoginKey);
+                localWriter.append("externalLoginKey=");
+                localWriter.append(externalLoginKey);
             }
         } else if ("content".equals(targetType)) {
-            appendContentUrl(writer, localRequestName, request);
+            appendContentUrl(localWriter, localRequestName, request);
         } else if ("plain".equals(targetType)) {
-            writer.append(localRequestName);
+            localWriter.append(localRequestName);
         } else {
-            writer.append(localRequestName);
+            localWriter.append(localRequestName);
+        }
+        
+        if (parameterList != null && parameterList.size() > 0) {
+            String localUrl = localWriter.toString();
+            externalWriter.append(localUrl);
+            boolean needsAmp = true;
+            if (localUrl.indexOf('?') == -1) {
+                externalWriter.append('?');
+                needsAmp = false;
+            }
+            
+            for (ModelFormField.Parameter parameter: parameterList) {
+                if (needsAmp) {
+                    externalWriter.append("&amp;");
+                } else {
+                    needsAmp = true;
+                }
+                externalWriter.append(parameter.getName());
+                externalWriter.append('=');
+                StringUtil.SimpleEncoder simpleEncoder = (StringUtil.SimpleEncoder) context.get("simpleEncoder");
+                if (simpleEncoder != null) {
+                    externalWriter.append(simpleEncoder.encode(parameter.getValue(context)));
+                } else {
+                    externalWriter.append(parameter.getValue(context));
+                }
+            }
+        } else {
+            externalWriter.append(localWriter.toString());
         }
-
     }
 
     public static void appendOfbizUrl(Appendable writer, String location, HttpServletRequest request, HttpServletResponse response) throws IOException {
@@ -78,7 +111,7 @@
         writer.append(location);
     }
 
-    public static void makeHyperlinkString(Appendable writer, String linkStyle, String targetType, String target, String description, HttpServletRequest request, HttpServletResponse response, Map<String, Object> context, String targetWindow, String event, String action) throws IOException {
+    public static void makeHyperlinkString(Appendable writer, String linkStyle, String targetType, String target, List<ModelFormField.Parameter> parameterList, String description, HttpServletRequest request, HttpServletResponse response, Map<String, Object> context, String targetWindow, String event, String action) throws IOException {
         if (UtilValidate.isNotEmpty(description) || UtilValidate.isNotEmpty(request.getAttribute("image"))) {
             writer.append("<a");
 
@@ -90,7 +123,7 @@
 
             writer.append(" href=\"");
 
-            buildHyperlinkUrl(writer, target, targetType, request, response, context);
+            buildHyperlinkUrl(writer, target, targetType, parameterList, request, response, context);
 
             writer.append("\"");
             
@@ -120,4 +153,83 @@
             writer.append("</a>");
         }
     }
+    
+    public static void makeHiddenFormLinkAnchor(Appendable writer, String linkStyle, String description, String event, String action, ModelFormField modelFormField, HttpServletRequest request, HttpServletResponse response, Map<String, Object> context) throws IOException {
+        if (UtilValidate.isNotEmpty(description) || UtilValidate.isNotEmpty(request.getAttribute("image"))) {
+            writer.append("<a");
+
+            if (UtilValidate.isNotEmpty(linkStyle)) {
+                writer.append(" class=\"");
+                writer.append(linkStyle);
+                writer.append("\"");
+            }
+
+            writer.append(" href=\"javascript:document.");
+            writer.append(makeLinkHiddenFormName(context, modelFormField));
+            writer.append(".submit()\"");
+            
+            if (UtilValidate.isNotEmpty(event) && UtilValidate.isNotEmpty(action)) {
+                writer.append(" ");
+                writer.append(event);
+                writer.append("=\"");
+                writer.append(action);
+                writer.append('"');
+            }
+
+            writer.append('>');
+            
+            if (UtilValidate.isNotEmpty(request.getAttribute("image"))){
+                writer.append("<img src=\"");
+                writer.append(request.getAttribute("image").toString());
+                writer.append("\"/>");
+            }
+
+            writer.append(description);
+            writer.append("</a>");
+        }
+    }
+    
+    public static void makeHiddenFormLinkForm(Appendable writer, String target, String targetType, String targetWindow, List<ModelFormField.Parameter> parameterList, ModelFormField modelFormField, HttpServletRequest request, HttpServletResponse response, Map<String, Object> context) throws IOException {
+        writer.append("<form method=\"post\"");
+        writer.append(" action=\"");
+        WidgetWorker.buildHyperlinkUrl(writer, target, targetType, null, request, response, context);
+        writer.append("\"");
+
+        if (UtilValidate.isNotEmpty(targetWindow)) {
+            writer.append(" target=\"");
+            writer.append(targetWindow);
+            writer.append("\"");
+        }
+
+        writer.append(" onSubmit=\"javascript:submitFormDisableSubmits(this)\"");
+
+        writer.append(" name=\"");
+        writer.append(makeLinkHiddenFormName(context, modelFormField));
+        writer.append("\">");
+
+        for (ModelFormField.Parameter parameter: parameterList) {
+            writer.append("<input name=\"");
+            writer.append(parameter.getName());
+            writer.append("\" value=\"");
+            writer.append(parameter.getValue(context));
+            writer.append("\" type=\"hidden\"/>");
+        }
+        
+        writer.append("</form>");
+    }
+    
+    public static String makeLinkHiddenFormName(Map<String, Object> context, ModelFormField modelFormField) {
+        ModelForm modelForm = modelFormField.getModelForm();
+        Integer itemIndex = (Integer) context.get("itemIndex");
+        String formName = (String) context.get("formName");
+        if (UtilValidate.isEmpty(formName)) {
+            formName = modelForm.getName();
+        }
+
+        if (itemIndex != null) {
+            return formName + modelForm.getItemIndexSeparator() + itemIndex.intValue() + modelForm.getItemIndexSeparator() + modelFormField.getName();
+        } else {
+            return formName + modelForm.getItemIndexSeparator() + modelFormField.getName();
+        }
+    }
 }

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=754626&r1=754625&r2=754626&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Sun Mar 15 07:41:31 2009
@@ -2514,11 +2514,11 @@
         return this.useRowSubmit;
     }
 
-    public List getMultiSubmitFields() {
+    public List<ModelFormField> getMultiSubmitFields() {
         return this.multiSubmitFields;
     }
 
-    public List getInbetweenList(FieldGroup startFieldGroup, FieldGroup endFieldGroup) {
+    public List<Object> getInbetweenList(FieldGroup startFieldGroup, FieldGroup endFieldGroup) {
         ArrayList<Object> inbetweenList = new ArrayList<Object>();
         boolean firstFound = false;
         String startFieldGroupId = null;

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java?rev=754626&r1=754625&r2=754626&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java Sun Mar 15 07:41:31 2009
@@ -995,7 +995,7 @@
             }
             
             // search for a localized label for the field's name
-            Map<String, String> uiLabelMap = (Map) context.get("uiLabelMap");
+            Map<String, String> uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap"));
             if (uiLabelMap != null) {
                 String titleFieldName = "FormFieldTitle_" + this.name;
                 String localizedName = (String) uiLabelMap.get(titleFieldName);
@@ -2199,16 +2199,51 @@
             this.subHyperlink = newSubHyperlink;
         }
     }
+    
+    public static class Parameter {
+        protected String name;
+        protected FlexibleStringExpander value;
+        protected FlexibleMapAccessor<Object> fromField;
+
+        public Parameter(Element element) {
+            this.name = element.getAttribute("param-name");
+            this.value = UtilValidate.isNotEmpty(element.getAttribute("value")) ? FlexibleStringExpander.getInstance(element.getAttribute("value")) : null;
+            this.fromField = UtilValidate.isNotEmpty(element.getAttribute("from-field")) ? FlexibleMapAccessor.getInstance(element.getAttribute("from-field")) : null;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public String getValue(Map<String, Object> context) {
+            if (this.value != null) {
+                return this.value.expandString(context);
+            } else if (this.fromField != null) {
+                Object contextVal = this.fromField.get(context);
+                return contextVal.toString();
+            } else {
+                // as a last chance try finding a context field with the key of the name field
+                Object obj = context.get(this.name);
+                if (obj != null) {
+                    return obj.toString();
+                } else {
+                    return null;
+                }
+            }
+        }
+    }
 
     public static class HyperlinkField extends FieldInfo {
         public static String DEFAULT_TARGET_TYPE = "intra-app";
 
         protected boolean alsoHidden = true;
+        protected String linkType;
         protected String targetType;
         protected String image;
         protected FlexibleStringExpander target;
         protected FlexibleStringExpander description;
         protected FlexibleStringExpander targetWindowExdr;
+        protected List<Parameter> parameterList = FastList.newInstance();
 
         protected HyperlinkField() {
             super();
@@ -2228,9 +2263,15 @@
             this.setDescription(element.getAttribute("description"));
             this.setTarget(element.getAttribute("target"));
             this.alsoHidden = !"false".equals(element.getAttribute("also-hidden"));
+            this.linkType = element.getAttribute("link-type");
             this.targetType = element.getAttribute("target-type");
             this.targetWindowExdr = FlexibleStringExpander.getInstance(element.getAttribute("target-window"));
             this.image = element.getAttribute("image-location");
+            
+            List<? extends Element> parameterElementList = UtilXml.childElementList(element, "parameter");
+            for (Element parameterElement: parameterElementList) {
+                this.parameterList.add(new Parameter(parameterElement));
+            }
         }
 
         public void renderFieldString(Appendable writer, Map<String, Object> context, FormStringRenderer formStringRenderer) throws IOException {
@@ -2241,6 +2282,10 @@
             return this.alsoHidden;
         }
 
+        public String getLinkType() {
+            return this.linkType;
+        }
+        
         public String getTargetType() {
             if (UtilValidate.isNotEmpty(this.targetType)) {
                 return this.targetType;
@@ -2262,6 +2307,10 @@
             return this.target.expandString(context);
         }
         
+        public List<Parameter> getParameterList() {
+            return this.parameterList;
+        }
+        
         public String getImage() {
          return this.image;
         }

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java?rev=754626&r1=754625&r2=754626&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java Sun Mar 15 07:41:31 2009
@@ -335,15 +335,20 @@
     public void renderHyperlinkField(Appendable writer, Map<String, Object> context, HyperlinkField hyperlinkField) throws IOException {
      this.request.setAttribute("image", hyperlinkField.getImage());
         ModelFormField modelFormField = hyperlinkField.getModelFormField();
-        this.makeHyperlinkString(
-            writer,
-            modelFormField.getWidgetStyle(),
-            hyperlinkField.getTargetType(),
-            hyperlinkField.getTarget(context),
-            hyperlinkField.getDescription(context),
-            hyperlinkField.getTargetWindow(context),
-            modelFormField.getEvent(),
-            modelFormField.getAction(context));
+        if ("hidden-form".equals(hyperlinkField.getLinkType())) {
+            if ("multi".equals(modelFormField.getModelForm().getType())) {
+                WidgetWorker.makeHyperlinkString(writer, modelFormField.getWidgetStyle(), hyperlinkField.getTargetType(), hyperlinkField.getTarget(context), hyperlinkField.getParameterList(), hyperlinkField.getDescription(context), this.request, this.response, context, hyperlinkField.getTargetWindow(context), modelFormField.getEvent(), modelFormField.getAction(context));
+                
+                //WidgetWorker.makeHiddenFormLinkAnchor(writer, modelFormField.getWidgetStyle(), hyperlinkField.getDescription(context), modelFormField.getEvent(), modelFormField.getAction(context), modelFormField, this.request, this.response, context);
+                // TODO: this is a bit trickier, since we can't do a nested form we'll have to put the link to submit the form in place, but put the actual form def elsewhere, ie after the big form is closed
+                //WidgetWorker.makeHiddenFormLinkForm(writer, hyperlinkField.getTarget(context), hyperlinkField.getTargetType(), hyperlinkField.getTargetWindow(context), hyperlinkField.getParameterList(), modelFormField, this.request, this.response, context);
+            } else {
+                WidgetWorker.makeHiddenFormLinkForm(writer, hyperlinkField.getTarget(context), hyperlinkField.getTargetType(), hyperlinkField.getTargetWindow(context), hyperlinkField.getParameterList(), modelFormField, this.request, this.response, context);
+                WidgetWorker.makeHiddenFormLinkAnchor(writer, modelFormField.getWidgetStyle(), hyperlinkField.getDescription(context), modelFormField.getEvent(), modelFormField.getAction(context), modelFormField, this.request, this.response, context);
+            }
+        } else {
+            WidgetWorker.makeHyperlinkString(writer, modelFormField.getWidgetStyle(), hyperlinkField.getTargetType(), hyperlinkField.getTarget(context), hyperlinkField.getParameterList(), hyperlinkField.getDescription(context), this.request, this.response, context, hyperlinkField.getTargetWindow(context), modelFormField.getEvent(), modelFormField.getAction(context));
+        }
         this.appendTooltip(writer, context, modelFormField);
         //appendWhitespace(writer);
     }
@@ -354,21 +359,10 @@
         }
         if (subHyperlink.shouldUse(context)) {
             writer.append(' ');
-            this.makeHyperlinkString(
-                writer,
-                subHyperlink.getLinkStyle(),
-                subHyperlink.getTargetType(),
-                subHyperlink.getTarget(context),
-                subHyperlink.getDescription(context),
-                subHyperlink.getTargetWindow(context),
-                null, null);
+            WidgetWorker.makeHyperlinkString(writer, subHyperlink.getLinkStyle(), subHyperlink.getTargetType(), subHyperlink.getTarget(context), null, subHyperlink.getDescription(context), this.request, this.response, context, subHyperlink.getTargetWindow(context), null, null);
         }
     }
 
-    public void makeHyperlinkString(Appendable writer, String linkStyle, String targetType, String target, String description, String targetWindow, String event, String action) throws IOException {
-        WidgetWorker.makeHyperlinkString(writer, linkStyle, targetType, target, description, this.request, this.response, null, targetWindow, event, action);
-    }
-
     /* (non-Javadoc)
      * @see org.ofbiz.widget.form.FormStringRenderer#renderTextField(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelFormField.TextField)
      */
@@ -522,7 +516,7 @@
         String paramName = modelFormField.getParameterName(context);
         String defaultDateTimeString = dateTimeField.getDefaultDateTimeString(context);
         
-        Map uiLabelMap = (Map) context.get("uiLabelMap");
+        Map<String, String> uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap"));
         if (uiLabelMap == null) {
             Debug.logWarning("Could not find uiLabelMap in context", module);
         }
@@ -872,7 +866,7 @@
             }
 
             // list out all options according to the option list
-            Iterator optionValueIter = allOptionValues.iterator();
+            Iterator<ModelFormField.OptionValue> optionValueIter = allOptionValues.iterator();
             while (optionValueIter.hasNext()) {
                 ModelFormField.OptionValue optionValue = (ModelFormField.OptionValue) optionValueIter.next();
                 String noCurrentSelectedKey = dropDownField.getNoCurrentSelectedKey(context);
@@ -898,7 +892,7 @@
             if (otherFieldSize > 0) {
             
                 String fieldName = modelFormField.getParameterName(context);
-                Map dataMap = modelFormField.getMap(context);
+                Map<String, Object> dataMap = UtilGenerics.checkMap(modelFormField.getMap(context));
                 if (dataMap == null) {
                     dataMap = context;
                 }
@@ -956,12 +950,12 @@
         String currentValue = modelFormField.getEntry(context);
         Boolean allChecked = checkField.isAllChecked(context);
         
-        List allOptionValues = checkField.getAllOptionValues(context, modelForm.getDelegator(context));
+        List<ModelFormField.OptionValue> allOptionValues = checkField.getAllOptionValues(context, modelForm.getDelegator(context));
         String event = modelFormField.getEvent();
         String action = modelFormField.getAction(context);
 
         // list out all options according to the option list
-        Iterator optionValueIter = allOptionValues.iterator();
+        Iterator<ModelFormField.OptionValue> optionValueIter = allOptionValues.iterator();
         while (optionValueIter.hasNext()) {
             ModelFormField.OptionValue optionValue = (ModelFormField.OptionValue) optionValueIter.next();
 
@@ -1008,13 +1002,13 @@
     public void renderRadioField(Appendable writer, Map<String, Object> context, RadioField radioField) throws IOException {
         ModelFormField modelFormField = radioField.getModelFormField();
         ModelForm modelForm = modelFormField.getModelForm();
-        List allOptionValues = radioField.getAllOptionValues(context, modelForm.getDelegator(context));
+        List<ModelFormField.OptionValue> allOptionValues = radioField.getAllOptionValues(context, modelForm.getDelegator(context));
         String currentValue = modelFormField.getEntry(context);
         String event = modelFormField.getEvent();
         String action = modelFormField.getAction(context);
 
         // list out all options according to the option list
-        Iterator optionValueIter = allOptionValues.iterator();
+        Iterator<ModelFormField.OptionValue> optionValueIter = allOptionValues.iterator();
         while (optionValueIter.hasNext()) {
             ModelFormField.OptionValue optionValue = (ModelFormField.OptionValue) optionValueIter.next();
 
@@ -1296,7 +1290,7 @@
      * @see org.ofbiz.widget.form.FormStringRenderer#renderFormOpen(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm)
      */
     public void renderFormOpen(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException {
-        renderBeginningBoundaryComment(writer, "Form Widget", modelForm);
+        renderBeginningBoundaryComment(writer, "Form Widget - Form Element", modelForm);
         writer.append("<form method=\"post\" ");
         String targetType = modelForm.getTargetType();
         String targ = modelForm.getTarget(context, targetType);
@@ -1305,7 +1299,7 @@
         writer.append(" action=\"");
         if (targ != null && targ.length() > 0) {
             //this.appendOfbizUrl(writer, "/" + targ);
-            WidgetWorker.buildHyperlinkUrl(writer, targ, targetType, request, response, context);
+            WidgetWorker.buildHyperlinkUrl(writer, targ, targetType, null, request, response, context);
         }
         writer.append("\" ");
 
@@ -1371,16 +1365,16 @@
             writer.append("</script>");
         }
         appendWhitespace(writer);
-        renderEndingBoundaryComment(writer, "Form Widget", modelForm);
+        renderEndingBoundaryComment(writer, "Form Widget - Form Element", modelForm);
     }
 
     /* (non-Javadoc)
      * @see org.ofbiz.widget.form.FormStringRenderer#renderFormClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm)
      */
     public void renderMultiFormClose(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException {
-        Iterator submitFields = modelForm.getMultiSubmitFields().iterator();
+        Iterator<ModelFormField> submitFields = modelForm.getMultiSubmitFields().iterator();
         while (submitFields.hasNext()) {
-            ModelFormField submitField = (ModelFormField)submitFields.next();
+            ModelFormField submitField = (ModelFormField) submitFields.next();
             if (submitField != null) {
 
                 // Threw this in that as a hack to keep the submit button from expanding the first field
@@ -1974,7 +1968,7 @@
         String opUpThruDay = UtilProperties.getMessage("conditional", "up_thru_day", locale);
         String opIsEmpty = UtilProperties.getMessage("conditional", "is_empty", locale);
 
-        Map uiLabelMap = (Map) context.get("uiLabelMap");
+        Map<String, String> uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap"));
         if (uiLabelMap == null) {
             Debug.logWarning("Could not find uiLabelMap in context", module);
         }
@@ -2227,18 +2221,14 @@
         }
         writer.append(appendExternalLoginKey(lookupField.getFormName(context)));
         writer.append("'");
-        List targetParameterList = lookupField.getTargetParameterList();
-        if (targetParameterList.size() > 0) {
-            Iterator targetParameterIter = targetParameterList.iterator();
-            while (targetParameterIter.hasNext()) {
-                String targetParameter = (String) targetParameterIter.next();
-                // named like: document.${formName}.${targetParameter}.value
-                writer.append(", document.");
-                writer.append(modelFormField.getModelForm().getCurrentFormName(context));
-                writer.append(".");
-                writer.append(targetParameter);
-                writer.append(".value");
-            }
+        List<String> targetParameterList = lookupField.getTargetParameterList();
+        for (String targetParameter: targetParameterList) {
+            // named like: document.${formName}.${targetParameter}.value
+            writer.append(", document.");
+            writer.append(modelFormField.getModelForm().getCurrentFormName(context));
+            writer.append(".");
+            writer.append(targetParameter);
+            writer.append(".value");
         }
         writer.append(");\">");
         writer.append("<img src=\"");
@@ -2292,7 +2282,7 @@
             return;
         }
 
-        // get the parametrized pagination index and size fields
+        // get the parameterized pagination index and size fields
         int paginatorNumber = modelForm.getPaginatorNumber(context);
         String viewIndexParam = modelForm.getPaginateIndexField(context);
         String viewSizeParam = modelForm.getPaginateSizeField(context);
@@ -2309,7 +2299,7 @@
         if (actualPageSize >= listSize && listSize >= 0) return;
 
         // needed for the "Page" and "rows" labels
-        Map uiLabelMap = (Map) context.get("uiLabelMap");
+        Map<String, String> uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap"));
         String pageLabel = "";
         String commonDisplaying = "";
         if (uiLabelMap == null) {
@@ -2747,7 +2737,7 @@
                 String expandToolTip = null;
                 String collapseToolTip = null;
                 Map<String, Object> uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap"));
-                Map<String, Object> paramMap = UtilGenerics.checkMap(context.get("requestParameters"));
+                //Map<String, Object> paramMap = UtilGenerics.checkMap(context.get("requestParameters"));
                 if (uiLabelMap != null) {
                     expandToolTip = (String) uiLabelMap.get("CommonExpand");
                     collapseToolTip = (String) uiLabelMap.get("CommonCollapse");
@@ -2873,7 +2863,7 @@
             if (UtilValidate.isNotEmpty(targetBuffer.toString()) && targetBuffer.toString().toLowerCase().startsWith("javascript:")) {
                 targetType="plain";
             }
-            makeHyperlinkString(writer, modelFormField.getHeaderLinkStyle(), targetType, targetBuffer.toString(), titleText, null, null, null);
+            WidgetWorker.makeHyperlinkString(writer, modelFormField.getHeaderLinkStyle(), targetType, targetBuffer.toString(), null, titleText, this.request, this.response, null, null, null, null);
         } else if (modelFormField.isSortField()) {
             renderSortField (writer, context, modelFormField, titleText);        
         } else if (modelFormField.isRowSubmit()) {