You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by bu...@apache.org on 2010/04/17 18:10:24 UTC

svn commit: r935197 - in /ofbiz/trunk/framework/widget: src/org/ofbiz/widget/form/MacroFormRenderer.java src/org/ofbiz/widget/form/ModelFormField.java src/org/ofbiz/widget/html/HtmlFormRenderer.java templates/htmlFormMacroLibrary.ftl

Author: buscob
Date: Sat Apr 17 16:10:24 2010
New Revision: 935197

URL: http://svn.apache.org/viewvc?rev=935197&view=rev
Log:
A slightly changed (tabs replaced with spaces) patch from Blas Rodriguez Somoza
OFBIZ-3671 - XHTML validation errors (framework/widget) In xml (xhtml) ID must be unique
https://issues.apache.org/jira/browse/OFBIZ-3671

In XML id is a special attribute which must be unique.

    * ModelFormField.java must have the method getCurrentContainerId which is already on ModelForm
    * MacroFormRendered and HtmlFormRenderer must be modified to use the getCurrentContainerID instead of getIdName
    * htmlFormMacroLibrary. span id must be different from the associated hidden field.

Also:

htmlFormMacroLibrary
Line 73: readonly attribute without value.
Lines 102.103: better formatted, more readable javascript call.

Modified:
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java
    ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java?rev=935197&r1=935196&r2=935197&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java Sat Apr 17 16:10:24 2010
@@ -371,7 +371,7 @@ public class MacroFormRenderer implement
         }
         String event = modelFormField.getEvent();
         String action = modelFormField.getAction(context);
-        String id = modelFormField.getIdName();
+        String id = modelFormField.getCurrentContainerId(context);
         String clientAutocomplete = "false";
 
         List<ModelForm.UpdateArea> updateAreas = modelFormField.getOnChangeUpdateAreas();
@@ -432,7 +432,7 @@ public class MacroFormRenderer implement
         String name = modelFormField.getParameterName(context);
         String cols = Integer.toString(textareaField.getCols());
         String rows = Integer.toString(textareaField.getRows());
-        String id = modelFormField.getIdName();
+        String id = modelFormField.getCurrentContainerId(context);
         String className = "";
         String alert = "false";
         if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) {
@@ -537,7 +537,7 @@ public class MacroFormRenderer implement
                 value = value.substring(0, maxlength);
             }
         }
-        String id = modelFormField.getIdName();
+        String id = modelFormField.getCurrentContainerId(context);
         String formName = modelFormField.getModelForm().getCurrentFormName(context);
         String timeDropdown = dateTimeField.getInputMethod();
         String timeDropdownParamName = "";
@@ -680,7 +680,7 @@ public class MacroFormRenderer implement
         String className = "";
         String alert = "false";
         String name = modelFormField.getParameterName(context);
-        String id = modelFormField.getIdName();
+        String id = modelFormField.getCurrentContainerId(context);
         String multiple = dropDownField.isAllowMultiple()? "multiple": "";
         String otherFieldName = "";
         String formName = modelForm.getName();
@@ -1117,7 +1117,7 @@ public class MacroFormRenderer implement
         String name = modelFormField.getParameterName(context);
         String action = modelFormField.getAction(context);
         String event = modelFormField.getEvent();
-        String id = modelFormField.getIdName();
+        String id = modelFormField.getCurrentContainerId(context);
 
         StringWriter sr = new StringWriter();
         sr.append("<@renderHiddenField ");
@@ -1926,7 +1926,7 @@ public class MacroFormRenderer implement
         }
         String size = Integer.toString(lookupField.getSize());
         Integer maxlength = lookupField.getMaxlength();
-        String id = modelFormField.getIdName();
+        String id = modelFormField.getCurrentContainerId(context);
 
         List<ModelForm.UpdateArea> updateAreas = modelFormField.getOnChangeUpdateAreas();
 
@@ -1938,7 +1938,7 @@ public class MacroFormRenderer implement
             } else {
                 autoCompleterTarget = lookupFieldFormName + "&amp;amp;";
             }
-            autoCompleterTarget = autoCompleterTarget + "ajaxLookup=Y&amp;searchValueField=" + lookupField.getModelFormField().getParameterName(context);
+            autoCompleterTarget = autoCompleterTarget + "ajaxLookup=Y&amp;amp;searchValueField=" + lookupField.getModelFormField().getParameterName(context);
             updateAreas = FastList.newInstance();
             updateAreas.add(new ModelForm.UpdateArea("change", id, autoCompleterTarget));
         }
@@ -2158,6 +2158,10 @@ public class MacroFormRenderer implement
         String prepLinkText = UtilHttp.getQueryStringFromTarget(targetService);
         String prepLinkSizeText;
 
+        if (UtilValidate.isNotEmpty(queryString)) {
+            queryString = UtilHttp.encodeAmpersands(queryString);
+        }
+        
         if (prepLinkText == null) {
             prepLinkText = "";
         }
@@ -2391,7 +2395,7 @@ public class MacroFormRenderer implement
         String name = modelFormField.getParameterName(context);
         String size = Integer.toString(passwordField.getSize());
         String maxlength = "";
-        String id = modelFormField.getIdName();
+        String id = modelFormField.getCurrentContainerId(context);
         String autocomplete = "";
         if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) {
             className = modelFormField.getWidgetStyle();

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=935197&r1=935196&r2=935197&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 Sat Apr 17 16:10:24 2010
@@ -1103,6 +1103,19 @@ public class ModelFormField {
         }
     }
 
+    public String getCurrentContainerId(Map<String, Object> context) {
+        ModelForm modelForm = this.getModelForm();
+        if (modelForm != null) {
+            Integer itemIndex = (Integer) context.get("itemIndex");
+            if (modelForm != null && ("list".equals(modelForm.getType()) || "multi".equals(modelForm.getType() ))) {
+                if (itemIndex != null) {
+                    return this.getIdName() + modelForm.getItemIndexSeparator() + itemIndex.intValue();
+                }
+            }
+        }
+        return this.getIdName();
+    }
+
     public String getHeaderLink() {
         return headerLink;
     }

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=935197&r1=935196&r2=935197&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 Sat Apr 17 16:10:24 2010
@@ -161,14 +161,10 @@ public class HtmlFormRenderer extends Ht
      */
     public void renderDisplayField(Appendable writer, Map<String, Object> context, DisplayField displayField) throws IOException {
         ModelFormField modelFormField = displayField.getModelFormField();
-        ModelForm modelForm = modelFormField.getModelForm();
 
         StringBuilder str = new StringBuilder();
 
-        String idName = modelFormField.getIdName();
-        if (UtilValidate.isNotEmpty(idName) && ("list".equals(modelForm.getType()) || "multi".equals(modelForm.getType()))) {
-            idName += "_" + modelForm.getRowCount();
-        }
+        String idName = modelFormField.getCurrentContainerId(context);
 
         if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle()) || modelFormField.shouldBeRed(context)) {
             str.append("<span class=\"");
@@ -180,7 +176,7 @@ public class HtmlFormRenderer extends Ht
             str.append('"');
             if (UtilValidate.isNotEmpty(idName)) {
                 str.append(" id=\"");
-                str.append(idName);
+                str.append(idName+"_sp");
                 str.append('"');
             }
             str.append('>');
@@ -401,7 +397,7 @@ public class HtmlFormRenderer extends Ht
             writer.append('"');
         }
 
-        String idName = modelFormField.getIdName();
+        String idName = modelFormField.getCurrentContainerId(context);
         if (UtilValidate.isNotEmpty(idName)) {
             writer.append(" id=\"");
             writer.append(idName);
@@ -465,7 +461,7 @@ public class HtmlFormRenderer extends Ht
         writer.append(Integer.toString(textareaField.getRows()));
         writer.append('"');
 
-        String idName = modelFormField.getIdName();
+        String idName = modelFormField.getCurrentContainerId(context);
         if (UtilValidate.isNotEmpty(idName)) {
             writer.append(" id=\"");
             writer.append(idName);
@@ -584,7 +580,7 @@ public class HtmlFormRenderer extends Ht
         writer.append(Integer.toString(maxlength));
         writer.append('"');
 
-        String idName = modelFormField.getIdName();
+        String idName = modelFormField.getCurrentContainerId(context);
         if (UtilValidate.isNotEmpty(idName)) {
             writer.append(" id=\"");
             writer.append(idName);
@@ -742,7 +738,7 @@ public class HtmlFormRenderer extends Ht
         writer.append(" name=\"");
         writer.append(modelFormField.getParameterName(context));
 
-        String idName = modelFormField.getIdName();
+        String idName = modelFormField.getCurrentContainerId(context);
 
         if (ajaxEnabled) {
             writer.append("_description\"");
@@ -1337,7 +1333,7 @@ public class HtmlFormRenderer extends Ht
             writer.append("\"");
         }
 
-        String containerId =  modelForm.getContainerId();
+        String containerId =  modelForm.getCurrentContainerId(context);
         if (UtilValidate.isNotEmpty(containerId)) {
             writer.append(" id=\"");
             writer.append(containerId);
@@ -2216,7 +2212,7 @@ public class HtmlFormRenderer extends Ht
             writer.append('"');
         }
 
-        String idName = modelFormField.getIdName();
+        String idName = modelFormField.getCurrentContainerId(context);
         if (UtilValidate.isNotEmpty(idName)) {
             writer.append(" id=\"");
             writer.append(idName);
@@ -2665,7 +2661,7 @@ public class HtmlFormRenderer extends Ht
             writer.append('"');
         }
 
-        String idName = modelFormField.getIdName();
+        String idName = modelFormField.getCurrentContainerId(context);
         if (UtilValidate.isNotEmpty(idName)) {
             writer.append(" id=\"");
             writer.append(idName);

Modified: ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl?rev=935197&r1=935196&r2=935197&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl (original)
+++ ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Sat Apr 17 16:10:24 2010
@@ -28,7 +28,7 @@ under the License.
         <img src="${imageLocation}"><#lt/>
     <#else>
         <#if inPlaceEditorUrl?has_content || class?has_content || alert=="true">
-            <span <#if idName?has_content>id="${idName}"</#if> <@renderClass class alert />><#t/>
+            <span <#if idName?has_content>id="cc_${idName}"</#if> <@renderClass class alert />><#t/>
         </#if>
         
         <#if description?has_content>
@@ -41,7 +41,7 @@ under the License.
         </#if>
         <#if inPlaceEditorUrl?has_content && idName?has_content>
             <script language="JavaScript" type="text/javascript"><#lt/>
-            ajaxInPlaceEditDisplayField('${idName}', '${inPlaceEditorUrl}', ${inPlaceEditorParams});<#lt/>
+            ajaxInPlaceEditDisplayField('cc_${idName}', '${inPlaceEditorUrl}', ${inPlaceEditorParams});<#lt/>
             </script><#lt/>
         </#if>
     </#if>
@@ -70,7 +70,7 @@ under the License.
     <#if cols?has_content> cols="${cols}"</#if><#rt/>
     <#if rows?has_content> rows="${rows}"</#if><#rt/>
     <#if id?has_content> id="${id}"</#if><#rt/>
-    <#if readonly?has_content> ${readonly}</#if><#rt/>
+    <#if readonly?has_content && readonly=='readonly'> readonly="readonly"</#if><#rt/>
     <#if maxlength?has_content> maxlength="${maxlength}"</#if><#rt/>
     ><#t/>
     <#if value?has_content>${value}</#if><#t/>
@@ -98,9 +98,9 @@ under the License.
           <#else>
              <a href="javascript:call_cal(document.<#rt/>
           </#if>
-          ${formName}.
-          <#if timeDropdownParamName?has_content>${timeDropdownParamName}</#if>
-          <#if defaultDateTimeString?has_content>,'${defaultDateTimeString}'</#if>);" 
+          ${formName}.<#t/>
+          <#if timeDropdownParamName?has_content>${timeDropdownParamName}</#if><#t/>
+          <#if defaultDateTimeString?has_content>,'${defaultDateTimeString}'</#if>);"<#lt/>
           title="<#if localizedIconTitle?has_content>${localizedIconTitle}</#if>"><#rt/>
           </a><#rt/>
         </li>