You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2017/05/09 09:33:52 UTC
svn commit: r1794513 - in /ofbiz/ofbiz-framework/trunk/framework/widget:
dtd/widget-common.xsd
src/main/java/org/apache/ofbiz/widget/model/AbstractModelAction.java
Author: jleroux
Date: Tue May 9 09:33:52 2017
New Revision: 1794513
URL: http://svn.apache.org/viewvc?rev=1794513&view=rev
Log:
Implemented: Add support for 'set-if-null' and 'set-if-empty' attributes on
screens for set element.
(OFBIZ-9251)
As stated in the discussion:
http://ofbiz.markmail.org/thread/hembr4hiabgwr7cs
"set-if-null" controls if field can be set to null and "set-if-empty" controls
if field can be set to an empty value. Both these attributes are supported by
"set" element of simple-method and similar support should be there on the screen.
jleroux: I fixed "if" formatting and added default="true" in widget-common.xsd
Thanks: Aditya Sharma
Modified:
ofbiz/ofbiz-framework/trunk/framework/widget/dtd/widget-common.xsd
ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelAction.java
Modified: ofbiz/ofbiz-framework/trunk/framework/widget/dtd/widget-common.xsd
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/dtd/widget-common.xsd?rev=1794513&r1=1794512&r2=1794513&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/dtd/widget-common.xsd (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/dtd/widget-common.xsd Tue May 9 09:33:52 2017
@@ -294,6 +294,24 @@ under the License.
</xs:restriction>
</xs:simpleType>
</xs:attribute>
+ <xs:attribute name="set-if-empty" type="xs:boolean" default="true">
+ <xs:annotation>
+ <xs:documentation>
+ Controls if the target field can be set to an empty value. The meaning of "empty" depends on the Java data type.
+ Defaults to "true".
+ Optional.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="set-if-null" type="xs:boolean" default="true">
+ <xs:annotation>
+ <xs:documentation>
+ Controls if the target field can be set to null when the from attribute evaluates to null.
+ Defaults to "true".
+ Optional.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="property-map" substitutionGroup="AllActions">
Modified: ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelAction.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelAction.java?rev=1794513&r1=1794512&r2=1794513&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelAction.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/widget/src/main/java/org/apache/ofbiz/widget/model/AbstractModelAction.java Tue May 9 09:33:52 2017
@@ -739,6 +739,8 @@ public abstract class AbstractModelActio
private final String toScope;
private final String type;
private final FlexibleStringExpander valueExdr;
+ private final boolean setIfNull;
+ private final boolean setIfEmpty;
public SetField(ModelWidget modelWidget, Element setElement) {
super(modelWidget, setElement);
@@ -750,6 +752,8 @@ public abstract class AbstractModelActio
this.type = setElement.getAttribute("type");
this.toScope = setElement.getAttribute("to-scope");
this.fromScope = setElement.getAttribute("from-scope");
+ this.setIfNull = !"false".equals(setElement.getAttribute("set-if-null")); //default to true
+ this.setIfEmpty = !"false".equals(setElement.getAttribute("set-if-empty")); //default to true
if (!this.fromField.isEmpty() && !this.valueExdr.isEmpty()) {
throw new IllegalArgumentException("Cannot specify a from-field [" + setElement.getAttribute("from-field")
+ "] and a value [" + setElement.getAttribute("value") + "] on the set action in a widget");
@@ -846,6 +850,16 @@ public abstract class AbstractModelActio
}
}
}
+ if (!setIfNull && newValue == null){
+ if (Debug.warningOn())
+ Debug.logWarning("Field value not found (null) for the field: [" + this.field.getOriginalName() + " and there was no default value, so field was not set", module);
+ return;
+ }
+ if (!setIfEmpty && ObjectType.isEmpty(newValue)){
+ if (Debug.warningOn())
+ Debug.logWarning("Field value not found (empty) for the field: [" + this.field.getOriginalName() + " and there was no default value, so field was not set", module);
+ return;
+ }
if (this.toScope != null && this.toScope.equals("user")) {
String originalName = this.field.getOriginalName();
List<String> currentWidgetTrail = UtilGenerics.toList(context.get("_WIDGETTRAIL_"));