[MGNLUI-2427] Select field options not updated when datasource changes Created: 19/Nov/13  Updated: 25/Jan/17  Resolved: 16/Nov/15

Status: Closed
Project: Magnolia UI
Component/s: app framework, forms
Affects Version/s: 5.3.11
Fix Version/s: 5.3.12, 5.4.4

Type: Bug Priority: Minor
Reporter: Marek Swiecznik Assignee: Ngoc Nguyenthanh
Resolution: Fixed Votes: 1
Labels: quickwin, support
Remaining Estimate: 2.5h
Time Spent: 1d 5.5h
Original Estimate: 2d

Issue Links:
Relates
relates to DOCU-639 Emphasize Select field support for "r... Closed
causality
relation
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:
Sprint: Basel 19
Story Points: 2

 Description   

Steps to reproduce:

  1. define a select field (SF) in a form (F), with path (P) and repository pointing to a options set.
  2. run form F, select field SF options should be ok
  3. add a node N in options set path P.
  4. run form F, select field SF options does not contain node N.

Expected behavour:
Select field SF options should contain node N.

Where is this bug/How to fix?
In SelectFieldFactory.getSelectFieldOptionDefinition changed order of blocks in if/else, so when path is defined, then build remote options first.

Patch:

SelectFieldFactory.java
diff --git a/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/factory/SelectFieldFactory.java b/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/factory/SelectFieldFactory.java
index ecd1ed4..a123c0c 100644
--- a/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/factory/SelectFieldFactory.java
+++ b/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/factory/SelectFieldFactory.java
@@ -159,7 +159,10 @@ public class SelectFieldFactory<D extends SelectFieldDefinition> extends Abstrac
     public List<SelectFieldOptionDefinition> getSelectFieldOptionDefinition() {
         List<SelectFieldOptionDefinition> res = new ArrayList<SelectFieldOptionDefinition>();
 
-        if (definition.getOptions() != null && !definition.getOptions().isEmpty()) {
+        if (StringUtils.isNotBlank(definition.getPath())) {
+            // Build an option based on the referred node.
+            buildRemoteOptions(res);
+        } else if (definition.getOptions() != null && !definition.getOptions().isEmpty()) {
             for (SelectFieldOptionDefinition option : definition.getOptions()) {
                 option.setValue(getValue(option));
                 option.setLabel(getMessage(getLabel(option)));
@@ -171,9 +174,6 @@ public class SelectFieldFactory<D extends SelectFieldDefinition> extends Abstrac
                 }
                 res.add(option);
             }
-        } else if (StringUtils.isNotBlank(definition.getPath())) {
-            // Build an option based on the referred node.
-            buildRemoteOptions(res);
         }
 
         return res;


 Comments   
Comment by Ngoc Nguyenthanh [ 16/Nov/15 ]

As current implementation of Select Field in info.magnolia.ui.form.field.factory.SelectFieldFactory#getSelectFieldOptionDefinition. It will check defined options in the field definition first. If the field options are empty or undefined then remote options will be applied. Vice versa it will use defined options without taking care of the 'path' property.
As current behavior in documentation for 'path' property

Path to an existing option set as opposed to defining options in the current definition.

I fixed by apply the patch. So if the 'path' property is set, then existed options of the field will be overridden by remote options.

Comment by Aleksandr Pchelintcev [ 20/Nov/15 ]

Copied from the Pull-request conversation:

After some further discussion, investigation and through reading of the issue statement - it appears that the patch actually only incidentally fixes the consequence, but not the problem itself:

  • What really happens is that when select field w/ remote options is created SelectFieldFactory#buildRemoteOptions() eventually sets the generated options to the definition object (definition.setOptions(res);)
  • Since definition is more or less a singleton - that value is persisted and later once the field is re-created the 'local' option collection isn't empty any longer => it is used and obviously whatever changes were made to the remote path are ignored
  • The patch I attached replaces the current solution with just a removal of the setting of generated options to the select field definition:
    • Shouldn't have any regression consequences on other field (first time it works the same, second time - it never worked =))
    • Eliminates alternation of definition object which is a bad thing (since it singleton and shared among users blabla)
    • I updated the test case to do check that the change of the remote path affects the generated option set
Generated at Mon Feb 12 08:56:30 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.