This is an automated email from the ASF dual-hosted git repository.
pandeypranay pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push:
new db50cbc908 Improved: Auto-generated indicator (Y/N) fields silently
default to "Y" and overwrite a NULL value on unrelated form saves (OFBIZ-13503)
(#2239)
db50cbc908 is described below
commit db50cbc908e9671f30a2e5f21729dc0ff25b6106
Author: Pranay Pandey <[email protected]>
AuthorDate: Tue Oct 13 11:09:55 2026 +0530
Improved: Auto-generated indicator (Y/N) fields silently default to "Y" and
overwrite a NULL value on unrelated form saves (OFBIZ-13503) (#2239)
Auto-generated create/update forms rendered indicator (Y/N) fields as a
drop-down with only "Y" and "N" options. For a nullable column holding
NULL, the browser preselected "Y", so saving any unrelated field on the
form silently persisted "Y" (e.g. ProductStore.allocateInventory).
OFBIZ-12001 addressed this for allocateInventory only; this change
applies to every auto-generated indicator field.
Changes:
- ModelFormFieldBuilder: indicator drop-downs on non-find forms now get
a blank option when the entity field is nullable. Not-null fields keep
only Y/N. Find forms already had the blank option and are unchanged.
- GenericEntity.set(): an empty string set on an indicator field is now
stored as null, so selecting the blank option persists NULL rather than
an empty string.
Side effects:
- Setting "" on a NOT NULL indicator field through GenericEntity.set()
now results in null and the store fails, instead of saving an empty
value. Auto-generated forms never submit a blank for such fields; only
hand-written forms or services passing "" would be affected.
---
.../main/java/org/apache/ofbiz/entity/GenericEntity.java | 3 +++
.../apache/ofbiz/widget/model/ModelFormFieldBuilder.java | 14 +++++++++++---
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git
a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
index 427444ba2a..deddc52a95 100644
--- a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
+++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
@@ -533,6 +533,9 @@ public class GenericEntity implements Map<String, Object>,
LocalizedMap<Object>,
+
this.getDelegator().getEntityGroupName(this.getEntityName()) + "]");
}
+ if (value instanceof String && ((String) value).isEmpty() &&
"indicator".equals(modelField.getType())) {
+ value = null;
+ }
if (value instanceof Boolean) {
// if this is a Boolean check to see if we should convert from
an indicator or just leave as is
try {
diff --git
a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormFieldBuilder.java
b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormFieldBuilder.java
index 2fdfbfdb4d..d6d833ff2c 100644
---
a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormFieldBuilder.java
+++
b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ModelFormFieldBuilder.java
@@ -795,9 +795,17 @@ public class ModelFormFieldBuilder {
this.setFieldInfo(hiddenField);
} else {
if ("indicator".equals(fieldType)) {
- List<OptionSource> optionSources = UtilMisc.toList(
- new ModelFormField.SingleOption("Y", null, null),
- new ModelFormField.SingleOption("N", null, null));
+ List<OptionSource> optionSources;
+ if (modelField.getIsNotNull()) {
+ optionSources = UtilMisc.toList(
+ new ModelFormField.SingleOption("Y", null, null),
+ new ModelFormField.SingleOption("N", null, null));
+ } else {
+ optionSources = UtilMisc.toList(
+ new ModelFormField.SingleOption("", null, null),
+ new ModelFormField.SingleOption("Y", null, null),
+ new ModelFormField.SingleOption("N", null, null));
+ }
ModelFormField.DropDownField dropDownField = new
ModelFormField.DropDownField(FieldInfo.SOURCE_AUTO_ENTITY,
optionSources);
this.setFieldInfo(dropDownField);