Author: jacopoc
Date: Tue Oct 9 23:34:13 2007
New Revision: 583366
URL:
http://svn.apache.org/viewvc?rev=583366&view=revLog:
Added support for default-value attribute to the set operation in form widget actions.
Modified:
ofbiz/trunk/framework/widget/dtd/widget-form.xsd
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.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=583366&r1=583365&r2=583366&view=diff==============================================================================
--- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original)
+++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Tue Oct 9 23:34:13 2007
@@ -1081,6 +1081,7 @@
<xs:attribute type="xs:string" name="field" use="required"/>
<xs:attribute type="xs:string" name="from-field"/>
<xs:attribute type="xs:string" name="value"/>
+ <xs:attribute type="xs:string" name="default-value"/>
<xs:attribute name="global" default="false">
<xs:simpleType>
<xs:restriction base="xs:token">
Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java?rev=583366&r1=583365&r2=583366&view=diff==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormAction.java Tue Oct 9 23:34:13 2007
@@ -108,6 +108,7 @@
protected FlexibleMapAccessor field;
protected FlexibleMapAccessor fromField;
protected FlexibleStringExpander valueExdr;
+ protected FlexibleStringExpander defaultExdr;
protected FlexibleStringExpander globalExdr;
protected String type;
@@ -116,6 +117,7 @@
this.field = new FlexibleMapAccessor(setElement.getAttribute("field"));
this.fromField = UtilValidate.isNotEmpty(setElement.getAttribute("from-field")) ? new FlexibleMapAccessor(setElement.getAttribute("from-field")) : null;
this.valueExdr = UtilValidate.isNotEmpty(setElement.getAttribute("value")) ? new FlexibleStringExpander(setElement.getAttribute("value")) : null;
+ this.defaultExdr = new FlexibleStringExpander(setElement.getAttribute("default-value"));
this.globalExdr = new FlexibleStringExpander(setElement.getAttribute("global"));
this.type = setElement.getAttribute("type");
if (this.fromField != null && this.valueExdr != null) {
@@ -135,6 +137,12 @@
} else if (this.valueExdr != null) {
newValue = this.valueExdr.expandString(context);
}
+
+ // If newValue is still empty, use the default value
+ if (ObjectType.isEmpty(newValue) && !this.defaultExdr.isEmpty()) {
+ newValue = this.defaultExdr.expandString(context);
+ }
+
if (UtilValidate.isNotEmpty(this.type)) {
try {
newValue = ObjectType.simpleTypeConvert(newValue, this.type, null, null);