svn commit: r754811 - in /ofbiz/trunk/framework/widget: dtd/widget-form.xsd src/org/ofbiz/widget/WidgetWorker.java src/org/ofbiz/widget/form/ModelFormField.java src/org/ofbiz/widget/html/HtmlFormRenderer.java

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

svn commit: r754811 - in /ofbiz/trunk/framework/widget: dtd/widget-form.xsd src/org/ofbiz/widget/WidgetWorker.java src/org/ofbiz/widget/form/ModelFormField.java src/org/ofbiz/widget/html/HtmlFormRenderer.java

jonesde
Author: jonesde
Date: Mon Mar 16 03:53:52 2009
New Revision: 754811

URL: http://svn.apache.org/viewvc?rev=754811&view=rev
Log:
Added support for the parameter sub-element and the link-type attribute to the sub-hyperlink element, though all of them seem to go to links and not to requests that call services so this isn't needed as far as I can tell so far

Modified:
    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/ModelFormField.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java

Modified: ofbiz/trunk/framework/widget/dtd/widget-form.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-form.xsd?rev=754811&r1=754810&r2=754811&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original)
+++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Mon Mar 16 03:53:52 2009
@@ -1382,12 +1382,23 @@
     </xs:attributeGroup>
     <xs:element name="sub-hyperlink">
         <xs:complexType>
+            <xs:sequence>
+                <xs:element minOccurs="0" maxOccurs="unbounded" ref="parameter"/>
+            </xs:sequence>
             <xs:attributeGroup ref="attlist.sub-hyperlink"/>
         </xs:complexType>
     </xs:element>
     <xs:attributeGroup name="attlist.sub-hyperlink">
         <xs:attribute type="xs:string" name="use-when"/>
         <xs:attribute type="xs:string" name="link-style"/>
+        <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">

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=754811&r1=754810&r2=754811&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetWorker.java Mon Mar 16 03:53:52 2009
@@ -28,6 +28,7 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.ofbiz.base.util.StringUtil;
+import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilHttp;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.webapp.control.RequestHandler;
@@ -111,7 +112,34 @@
         writer.append(location);
     }
 
-    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 {
+    public static void makeHyperlinkByType(Appendable writer, String linkType, String linkStyle, String targetType, String target,
+            List<ModelFormField.Parameter> parameterList, String description, String targetWindow, ModelFormField modelFormField,
+            HttpServletRequest request, HttpServletResponse response, Map<String, Object> context) throws IOException {
+        if ("hidden-form".equals(linkType)) {
+            if ("multi".equals(modelFormField.getModelForm().getType())) {
+                WidgetWorker.makeHiddenFormLinkAnchor(writer, linkStyle, description, modelFormField, request, response, context);
+
+                // 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
+                Map<String, Object> wholeFormContext = UtilGenerics.checkMap(context.get("wholeFormContext"));
+                Appendable postMultiFormWriter = wholeFormContext != null ? (Appendable) wholeFormContext.get("postMultiFormWriter") : null;
+                if (postMultiFormWriter == null) {
+                    postMultiFormWriter = new StringWriter();
+                    wholeFormContext.put("postMultiFormWriter", postMultiFormWriter);
+                }
+                WidgetWorker.makeHiddenFormLinkForm(postMultiFormWriter, target, targetType, targetWindow, parameterList, modelFormField, request, response, context);
+            } else {
+                WidgetWorker.makeHiddenFormLinkForm(writer, target, targetType, targetWindow, parameterList, modelFormField, request, response, context);
+                WidgetWorker.makeHiddenFormLinkAnchor(writer, linkStyle, description, modelFormField, request, response, context);
+            }
+        } else {
+            WidgetWorker.makeHyperlinkString(writer, linkStyle, targetType, target, parameterList, description, modelFormField, request, response, context, targetWindow);
+        }
+        
+    }
+    
+    public static void makeHyperlinkString(Appendable writer, String linkStyle, String targetType, String target, List<ModelFormField.Parameter> parameterList,
+            String description, ModelFormField modelFormField, HttpServletRequest request, HttpServletResponse response, Map<String, Object> context, String targetWindow)
+            throws IOException {
         if (UtilValidate.isNotEmpty(description) || UtilValidate.isNotEmpty(request.getAttribute("image"))) {
             writer.append("<a");
 
@@ -133,11 +161,11 @@
                 writer.append("\"");
             }
 
-            if (UtilValidate.isNotEmpty(event) && UtilValidate.isNotEmpty(action)) {
+            if (UtilValidate.isNotEmpty(modelFormField.getEvent()) && UtilValidate.isNotEmpty(modelFormField.getAction(context))) {
                 writer.append(" ");
-                writer.append(event);
+                writer.append(modelFormField.getEvent());
                 writer.append("=\"");
-                writer.append(action);
+                writer.append(modelFormField.getAction(context));
                 writer.append('"');
             }
 
@@ -154,7 +182,7 @@
         }
     }
     
-    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 {
+    public static void makeHiddenFormLinkAnchor(Appendable writer, String linkStyle, String description, ModelFormField modelFormField, HttpServletRequest request, HttpServletResponse response, Map<String, Object> context) throws IOException {
         if (UtilValidate.isNotEmpty(description) || UtilValidate.isNotEmpty(request.getAttribute("image"))) {
             writer.append("<a");
 
@@ -168,11 +196,11 @@
             writer.append(makeLinkHiddenFormName(context, modelFormField));
             writer.append(".submit()\"");
             
-            if (UtilValidate.isNotEmpty(event) && UtilValidate.isNotEmpty(action)) {
+            if (UtilValidate.isNotEmpty(modelFormField.getEvent()) && UtilValidate.isNotEmpty(modelFormField.getAction(context))) {
                 writer.append(" ");
-                writer.append(event);
+                writer.append(modelFormField.getEvent());
                 writer.append("=\"");
-                writer.append(action);
+                writer.append(modelFormField.getAction(context));
                 writer.append('"');
             }
 

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=754811&r1=754810&r2=754811&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 Mon Mar 16 03:53:52 2009
@@ -2150,7 +2150,7 @@
 
             Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink");
             if (subHyperlinkElement != null) {
-                this.subHyperlink = new SubHyperlink(subHyperlinkElement);
+                this.subHyperlink = new SubHyperlink(subHyperlinkElement, this.getModelFormField());
             }
         }
 
@@ -2346,21 +2346,36 @@
 
     public static class SubHyperlink {
         protected FlexibleStringExpander useWhen;
+        protected String linkType;
         protected String linkStyle;
         protected String targetType;
         protected FlexibleStringExpander target;
         protected FlexibleStringExpander description;
         protected FlexibleStringExpander targetWindowExdr;
+        protected List<Parameter> parameterList = FastList.newInstance();
+        protected ModelFormField modelFormField;
 
-        public SubHyperlink(Element element) {
+        public SubHyperlink(Element element, ModelFormField modelFormField) {
             this.setDescription(element.getAttribute("description"));
             this.setTarget(element.getAttribute("target"));
             this.setUseWhen(element.getAttribute("use-when"));
+            this.linkType = element.getAttribute("link-type");
             this.linkStyle = element.getAttribute("link-style");
             this.targetType = element.getAttribute("target-type");
             this.targetWindowExdr = FlexibleStringExpander.getInstance(element.getAttribute("target-window"));
+            
+            List<? extends Element> parameterElementList = UtilXml.childElementList(element, "parameter");
+            for (Element parameterElement: parameterElementList) {
+                this.parameterList.add(new Parameter(parameterElement));
+            }
+            
+            this.modelFormField = modelFormField;
         }
 
+        public String getLinkType() {
+            return this.linkType;
+        }
+        
         public String getLinkStyle() {
             return this.linkStyle;
         }
@@ -2393,6 +2408,10 @@
                 return "";
             }
         }
+        
+        public List<Parameter> getParameterList() {
+            return this.parameterList;
+        }
 
         public String getUseWhen(Map<String, Object> context) {
             if (this.useWhen != null) {
@@ -2401,6 +2420,10 @@
                 return "";
             }
         }
+        
+        public ModelFormField getModelFormField() {
+            return this.modelFormField;
+        }
 
         public boolean shouldUse(Map<String, Object> context) {
             boolean shouldUse = true;
@@ -2603,7 +2626,7 @@
 
             Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink");
             if (subHyperlinkElement != null) {
-                this.subHyperlink = new SubHyperlink(subHyperlinkElement);
+                this.subHyperlink = new SubHyperlink(subHyperlinkElement, this.getModelFormField());
             }
         }
 
@@ -2934,7 +2957,7 @@
 
             Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink");
             if (subHyperlinkElement != null) {
-                this.subHyperlink = new SubHyperlink(subHyperlinkElement);
+                this.subHyperlink = new SubHyperlink(subHyperlinkElement, this.getModelFormField());
             }
             
             Element autoCompleteElement = UtilXml.firstChildElement(element, "auto-complete");
@@ -3337,7 +3360,7 @@
 
             Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink");
             if (subHyperlinkElement != null) {
-                this.subHyperlink = new SubHyperlink(subHyperlinkElement);
+                this.subHyperlink = new SubHyperlink(subHyperlinkElement, this.getModelFormField());
             }
         }
 
@@ -3470,7 +3493,7 @@
 
             Element subHyperlinkElement = UtilXml.firstChildElement(element, "sub-hyperlink");
             if (subHyperlinkElement != null) {
-                this.subHyperlink = new SubHyperlink(subHyperlinkElement);
+                this.subHyperlink = new SubHyperlink(subHyperlinkElement, this.getModelFormField());
             }
         }
 

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=754811&r1=754810&r2=754811&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 Mon Mar 16 03:53:52 2009
@@ -336,25 +336,11 @@
     public void renderHyperlinkField(Appendable writer, Map<String, Object> context, HyperlinkField hyperlinkField) throws IOException {
      this.request.setAttribute("image", hyperlinkField.getImage());
         ModelFormField modelFormField = hyperlinkField.getModelFormField();
-        if ("hidden-form".equals(hyperlinkField.getLinkType())) {
-            if ("multi".equals(modelFormField.getModelForm().getType())) {
-                WidgetWorker.makeHiddenFormLinkAnchor(writer, modelFormField.getWidgetStyle(), hyperlinkField.getDescription(context), modelFormField.getEvent(), modelFormField.getAction(context), modelFormField, this.request, this.response, context);
-
-                // 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
-                Map<String, Object> wholeFormContext = UtilGenerics.checkMap(context.get("wholeFormContext"));
-                Appendable postMultiFormWriter = wholeFormContext != null ? (Appendable) wholeFormContext.get("postMultiFormWriter") : null;
-                if (postMultiFormWriter == null) {
-                    postMultiFormWriter = new StringWriter();
-                    wholeFormContext.put("postMultiFormWriter", postMultiFormWriter);
-                }
-                WidgetWorker.makeHiddenFormLinkForm(postMultiFormWriter, 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));
-        }
+        
+        WidgetWorker.makeHyperlinkByType(writer, hyperlinkField.getLinkType(), modelFormField.getWidgetStyle(), hyperlinkField.getTargetType(), hyperlinkField.getTarget(context),
+                hyperlinkField.getParameterList(), hyperlinkField.getDescription(context), hyperlinkField.getTargetWindow(context), modelFormField,
+                this.request, this.response, context);
+        
         this.appendTooltip(writer, context, modelFormField);
         //appendWhitespace(writer);
     }
@@ -365,7 +351,9 @@
         }
         if (subHyperlink.shouldUse(context)) {
             writer.append(' ');
-            WidgetWorker.makeHyperlinkString(writer, subHyperlink.getLinkStyle(), subHyperlink.getTargetType(), subHyperlink.getTarget(context), null, subHyperlink.getDescription(context), this.request, this.response, context, subHyperlink.getTargetWindow(context), null, null);
+            WidgetWorker.makeHyperlinkByType(writer, subHyperlink.getLinkType(), subHyperlink.getLinkStyle(), subHyperlink.getTargetType(), subHyperlink.getTarget(context),
+                    subHyperlink.getParameterList(), subHyperlink.getDescription(context), subHyperlink.getTargetWindow(context), subHyperlink.getModelFormField(),
+                    this.request, this.response, context);
         }
     }
 
@@ -2878,7 +2866,7 @@
             if (UtilValidate.isNotEmpty(targetBuffer.toString()) && targetBuffer.toString().toLowerCase().startsWith("javascript:")) {
                 targetType="plain";
             }
-            WidgetWorker.makeHyperlinkString(writer, modelFormField.getHeaderLinkStyle(), targetType, targetBuffer.toString(), null, titleText, this.request, this.response, null, null, null, null);
+            WidgetWorker.makeHyperlinkString(writer, modelFormField.getHeaderLinkStyle(), targetType, targetBuffer.toString(), null, titleText, modelFormField, this.request, this.response, null, null);
         } else if (modelFormField.isSortField()) {
             renderSortField (writer, context, modelFormField, titleText);        
         } else if (modelFormField.isRowSubmit()) {