WEB-INF/web.xml example:
+ * <context-param>
+ * <param-name>widgetVerbose</param-name>
+ * <param-value>true</param-value>
+ * </context-param>
+ *
+ * <actions>
+ * <set field="parameters.widgetVerbose" value="true" global="true"/>
+ * </actions>
+ *
+ */
+ public static final String enableBoundaryCommentsParam = "widgetVerbose";
+ protected String name;
+ protected boolean enableWidgetBoundaryComments = false;
+
+ protected ModelWidget() {}
+
+ /**
+ * Derived classes must call this constructor.
+ * @param widgetElement The XML Element for the widget
+ */
+ public ModelWidget(Element widgetElement) {
+ this.name = widgetElement.getAttribute("name");
+ }
+
+ /**
+ * Returns the widget's name.
+ * @return Widget's name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Returns the widget's name to be used in boundary comments. The default action
+ * is to return the widget's name. Derived classes can override this method to
+ * return a customized name.
+ * @return Name to be used in boundary comments
+ */
+ public String getBoundaryCommentName() {
+ return name;
+ }
+
+ /**
+ * Returns true if boundary comments are enabled for this widget, otherwise
+ * returns false.
+ * @return True if boundary comments are enabled for this widget
+ */
+ public boolean boundaryCommentsEnabled() {
+ return enableWidgetBoundaryComments;
+ }
+
+ /**
+ * Enables/disables boundary comments for this widget.
+ * @param context The screen rendering context
+ */
+ public void setWidgetBoundaryComments(Map context) {
+ enableWidgetBoundaryComments = widgetBoundaryCommentsEnabled((Map) context.get("parameters"));
+ }
+
+ /**
+ * Returns true if widget boundary comments are enabled. Widget boundary comments are
+ * enabled by setting widgetVerbose true in the parameters Map, or by setting
+ * widget.verbose=true in debug.properties.
+ * @param parameters Optional parameters Map
+ */
+ public static boolean widgetBoundaryCommentsEnabled(Map parameters) {
+ boolean result = "true".equals(UtilProperties.getPropertyValue("debug", "widget.verbose"));
+ if (!result && parameters != null) {
+ result = "true".equals(parameters.get(enableBoundaryCommentsParam));
+ }
+ return result;
+ }
+}
diff --git a/framework/widget/src/org/ofbiz/widget/form/FormFactory.java b/framework/widget/src/org/ofbiz/widget/form/FormFactory.java
index e591ceefab..0a09bf8984 100644
--- a/framework/widget/src/org/ofbiz/widget/form/FormFactory.java
+++ b/framework/widget/src/org/ofbiz/widget/form/FormFactory.java
@@ -65,7 +65,7 @@ public class FormFactory {
URL formFileUrl = null;
formFileUrl = FlexibleLocation.resolveLocation(resourceName); //, loader);
Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true);
- modelFormMap = readFormDocument(formFileDoc, delegator, dispatcher);
+ modelFormMap = readFormDocument(formFileDoc, delegator, dispatcher, resourceName);
formLocationCache.put(resourceName, modelFormMap);
}
}
@@ -95,7 +95,7 @@ public class FormFactory {
URL formFileUrl = servletContext.getResource(resourceName);
Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true);
- modelFormMap = readFormDocument(formFileDoc, delegator, dispatcher);
+ modelFormMap = readFormDocument(formFileDoc, delegator, dispatcher, cacheKey);
formWebappCache.put(cacheKey, modelFormMap);
}
}
@@ -108,7 +108,7 @@ public class FormFactory {
return modelForm;
}
- public static Map readFormDocument(Document formFileDoc, GenericDelegator delegator, LocalDispatcher dispatcher) {
+ public static Map readFormDocument(Document formFileDoc, GenericDelegator delegator, LocalDispatcher dispatcher, String formLocation) {
Map modelFormMap = new HashMap();
if (formFileDoc != null) {
// read document and construct ModelForm for each form element
@@ -118,6 +118,7 @@ public class FormFactory {
while (formElementIter.hasNext()) {
Element formElement = (Element) formElementIter.next();
ModelForm modelForm = new ModelForm(formElement, delegator, dispatcher);
+ modelForm.setFormLocation(formLocation);
modelFormMap.put(modelForm.getName(), modelForm);
}
}
diff --git a/framework/widget/src/org/ofbiz/widget/form/ModelForm.java b/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
index a0ef27ce0d..3492d049e7 100644
--- a/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
+++ b/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
@@ -52,13 +52,14 @@ import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ModelParam;
import org.ofbiz.service.ModelService;
+import org.ofbiz.widget.ModelWidget;
import org.w3c.dom.Element;
/**
* Widget Library - Form model class
*/
-public class ModelForm {
+public class ModelForm extends ModelWidget {
public static final String module = ModelForm.class.getName();
public static final String DEFAULT_FORM_RESULT_LIST_NAME = "defaultFormResultList";
@@ -66,7 +67,7 @@ public class ModelForm {
protected GenericDelegator delegator;
protected LocalDispatcher dispatcher;
- protected String name;
+ protected String formLocation;
protected String type;
protected FlexibleStringExpander target;
protected String targetType;
@@ -179,12 +180,14 @@ public class ModelForm {
/** XML Constructor */
public ModelForm(Element formElement, GenericDelegator delegator, LocalDispatcher dispatcher) {
+ super(formElement);
this.delegator = delegator;
this.dispatcher = dispatcher;
initForm(formElement);
}
public ModelForm(Element formElement) {
+ super(formElement);
initForm(formElement);
}
@@ -274,7 +277,6 @@ public class ModelForm {
}
}
- this.name = formElement.getAttribute("name");
if (this.type == null || formElement.hasAttribute("type")) {
this.type = formElement.getAttribute("type");
}
@@ -685,6 +687,8 @@ public class ModelForm {
public void renderFormString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) {
ModelFormAction.runSubActions(this.actions, context);
+ setWidgetBoundaryComments(context);
+
// if this is a list form, don't useRequestParameters
if ("list".equals(this.type) || "multi".equals(this.type)) {
context.put("useRequestParameters", Boolean.FALSE);
@@ -1905,6 +1909,10 @@ public class ModelForm {
return this.type;
}
+ public String getBoundaryCommentName() {
+ return formLocation + "#" + name;
+ }
+
public void resetBshInterpreter(Map context) {
context.remove("bshInterpreter");
}
@@ -2023,6 +2031,13 @@ public class ModelForm {
this.itemIndexSeparator = string;
}
+ /**
+ * @param string Form's location
+ */
+ public void setFormLocation(String formLocation) {
+ this.formLocation = formLocation;
+ }
+
/**
* @param string
*/
diff --git a/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java b/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
index 8486c1f1b4..610c1d56b5 100644
--- a/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
+++ b/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
@@ -1087,13 +1087,13 @@ public class ModelFormField {
condTrue = boolVal.booleanValue();
} else {
throw new IllegalArgumentException("Return value from use-when condition eval was not a Boolean: "
- + retVal.getClass().getName() + " [" + retVal + "] on the field " + this.name + " of form " + this.modelForm.name);
+ + retVal.getClass().getName() + " [" + retVal + "] on the field " + this.name + " of form " + this.modelForm.getName());
}
return condTrue;
} catch (EvalError e) {
String errMsg = "Error evaluating BeanShell use-when condition [" + useWhenStr + "] on the field "
- + this.name + " of form " + this.modelForm.name + ": " + e.toString();
+ + this.name + " of form " + this.modelForm.getName() + ": " + e.toString();
Debug.logError(e, errMsg, module);
//Debug.logError("For use-when eval error context is: " + context, module);
throw new IllegalArgumentException(errMsg);
diff --git a/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java b/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java
index ce9662baa8..3ded239dda 100644
--- a/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java
+++ b/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java
@@ -31,7 +31,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.UtilFormatOut;
import org.ofbiz.base.util.UtilHttp;
import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilValidate;
@@ -68,7 +67,7 @@ import org.apache.commons.lang.StringEscapeUtils;
/**
* Widget Library - HTML Form Renderer implementation
*/
-public class HtmlFormRenderer implements FormStringRenderer {
+public class HtmlFormRenderer extends HtmlWidgetRenderer implements FormStringRenderer {
public static final String module = HtmlFormRenderer.class.getName();
@@ -83,12 +82,6 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.response = response;
}
- public void appendWhitespace(StringBuffer buffer) {
- // appending line ends for now, but this could be replaced with a simple space or something
- buffer.append("\r\n");
- //buffer.append(' ');
- }
-
public void appendOfbizUrl(StringBuffer buffer, String location) {
ServletContext ctx = (ServletContext) this.request.getAttribute("servletContext");
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
@@ -184,7 +177,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
- //this.appendWhitespace(buffer);
+ //appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -202,7 +195,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
modelFormField.getEvent(),
modelFormField.getAction(context));
this.appendTooltip(buffer, context, modelFormField);
- //this.appendWhitespace(buffer);
+ //appendWhitespace(buffer);
}
public void makeHyperlinkString(StringBuffer buffer, ModelFormField.SubHyperlink subHyperlink, Map context) {
@@ -284,7 +277,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
- //this.appendWhitespace(buffer);
+ //appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -355,7 +348,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
- //this.appendWhitespace(buffer);
+ //appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -544,7 +537,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
- //this.appendWhitespace(buffer);
+ //appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -698,7 +691,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
- //this.appendWhitespace(buffer);
+ //appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -756,7 +749,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
- //this.appendWhitespace(buffer);
+ //appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -811,7 +804,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
- //this.appendWhitespace(buffer);
+ //appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -906,7 +899,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
- //this.appendWhitespace(buffer);
+ //appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -934,7 +927,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
- //this.appendWhitespace(buffer);
+ //appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -960,8 +953,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
}
buffer.append("/>");
-
- //this.appendWhitespace(buffer);
+ appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -996,7 +988,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
buffer.append("");
}
- //this.appendWhitespace(buffer);
+ //appendWhitespace(buffer);
}
}
@@ -1022,7 +1014,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
buffer.append("");
}
- //this.appendWhitespace(buffer);
+ //appendWhitespace(buffer);
} else {
renderFieldTitle(buffer, context, modelFormField);
}
@@ -1032,8 +1024,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
* @see org.ofbiz.widget.form.FormStringRenderer#renderFormOpen(java.lang.StringBuffer, java.util.Map, org.ofbiz.widget.form.ModelForm)
*/
public void renderFormOpen(StringBuffer buffer, Map context, ModelForm modelForm) {
- buffer.append("");
- this.appendWhitespace(buffer);
+ renderBeginningBoundaryComment(buffer, "Form Widget", modelForm);
buffer.append("");
String focusFieldName = modelForm.getfocusFieldName();
if (UtilValidate.isNotEmpty(focusFieldName)) {
- this.appendWhitespace(buffer);
+ appendWhitespace(buffer);
buffer.append("");
}
- this.appendWhitespace(buffer);
- buffer.append("");
-
- this.appendWhitespace(buffer);
+ appendWhitespace(buffer);
+ renderEndingBoundaryComment(buffer, "Form Widget", modelForm);
}
/* (non-Javadoc)
@@ -1145,10 +1134,8 @@ public class HtmlFormRenderer implements FormStringRenderer {
}
}
buffer.append("");
- this.appendWhitespace(buffer);
- buffer.append("");
-
- this.appendWhitespace(buffer);
+ appendWhitespace(buffer);
+ renderEndingBoundaryComment(buffer, "Form Widget", modelForm);
}
public void renderFormatListWrapperOpen(StringBuffer buffer, Map context, ModelForm modelForm) {
@@ -1166,8 +1153,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
}
context.put("_QBESTRING_", queryString);
- buffer.append("");
- this.appendWhitespace(buffer);
+ renderBeginningBoundaryComment(buffer, "Form Widget", modelForm);
this.renderNextPrev(buffer, context, modelForm);
buffer.append("