You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by pr...@apache.org on 2026/10/08 09:26:29 UTC
(ofbiz-framework) 01/01: Improved: Auto-generated indicator (Y/N) fields silently default to "Y" and overwrite a NULL value on unrelated form saves (OFBIZ-13503)
This is an automated email from the ASF dual-hosted git repository.
pandeypranay pushed a commit to branch OFBIZ-13503-indicator-field-default
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
commit 44aa0788121f53afa097238f58049512803f9ad3
Author: Pranay Pandey <pa...@users.noreply.github.com>
AuthorDate: Thu Oct 8 14:28:06 2026 +0530
Improved: Auto-generated indicator (Y/N) fields silently default to "Y" and overwrite a NULL value on unrelated form saves (OFBIZ-13503)
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 applies it
to every auto-generated indicator field.
- ModelFormFieldBuilder now adds a blank option to indicator drop-downs on non-find forms when the entity field is nullable; not-null fields keep only Y/N. Find forms already had the blank option.
- GenericEntity.set() now converts an empty string on an indicator field to null, so selecting the blank option stores NULL rather than an empty string. Note that setting "" on a not-null indicator field now fails instead of storing an empty value.
---
.../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);