Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Databound MultiComboBoxItem not applying optionCriteria

    SmartClient Version: v10.0p_2015-09-24/Pro Deployment (built 2015-09-24)

    Hi, I have a databound MultiComboBoxitem and I have set an optionCriteria on it, but for some reason this criteria is not being applied to the fetch request.

    It works for missingValues fetch requests but not for the regular one (when opening the picklist).

    I have added 2 screenshots of the DSRequests and as you can see the criteria (projectId & taskId) has been added to the missingValues request but not the other.
    Attached Files

    #2
    I am still having an issue with the MultiComboBoxItem not applying the optionCriteria on initial fetch (via autoFetchData) or when opening the picklist.

    Comment


      #3
      We're not seeing a general problem with optionCriteria not being sent with the PickList request, so we'll need a way to reproduce the problem in order to help.

      Comment


        #4
        Here is a TestCase that illustrates the problem.

        If you look at the 2 fetch requests that are being sent, the optionCriteria is only being applied to the missingValues request but not the other.

        TestCase:
        Code:
        final VLayout mainLayout = new VLayout();
        
        DynamicForm form = new DynamicForm();
        form.setWidth(400);
        
        DataSource optionDataSource = DataSource.get("optionDatasourceTest");
        
        MultiComboBoxItem item = new MultiComboBoxItem("comboBox");
        item.setOptionDataSource(optionDataSource);
        item.setDisplayField("display");
        item.setValueField("value");
        item.setAutoFetchData(true);
        item.setOptionCriteria(new Criteria("optionCriteria", "This should also be sent on autoFetchData."));
        item.setValue(new Integer[] { 4 });  // setting a non existing value to trigger missingValueFetch
        
        form.setItems(item);
        
        mainLayout.addMember(form);
        
        mainLayout.draw();
        optionDatasourceTest.ds.xml
        Code:
        <DataSource 
            ID="optionDatasourceTest" 
            serverConstructor="OptionDatasourceTestServlet">
            <fields>
                <field name="value"     type="sequence" primaryKey="true"    />
                <field name="display"     type="text"                         />
            </fields>
        </DataSource>
        OptionDatasourceTestServlet
        Code:
        import java.util.ArrayList;
        import java.util.Arrays;
        import java.util.HashMap;
        import java.util.List;
        import java.util.Map;
        
        import com.isomorphic.datasource.BasicDataSource;
        import com.isomorphic.datasource.DSRequest;
        import com.isomorphic.datasource.DSResponse;
        
        
        public class OptionDatasourceTestServlet extends BasicDataSource {
            
            public DSResponse executeFetch(DSRequest req) throws Exception {  
                List record = fetchRecord(req.getCriteria());  
                return new DSResponse(record);  
            }
          
            private List fetchRecord (Map criteria) {  
                
                System.out.println("Fetching with following criteria:");
                System.out.println(Arrays.toString(criteria.entrySet().toArray()));
                
                
                List<Map> response = new ArrayList<>();
        
                Map m1 = new HashMap<>();
                m1.put("value", 1);
                m1.put("display", "value1");
                Map m2 = new HashMap<>();
                m2.put("value", 2);
                m2.put("display", "value2");
                Map m3 = new HashMap<>();
                m3.put("value", 3);
                m3.put("display", "value3");
        
                response.add(m1);
                response.add(m2);
                response.add(m3);
                
                return response;  
            }
        }

        Comment


          #5
          With the test case as constructed, the problem appears to be that your criteria targets a field "optionCriteria" that doesn't exist in the DataSource. Technically, the fetchMissingValues requests should also be dropping this unrecognized criteria, but they go through a different codepath that doesn't perform this check client-side.

          Comment


            #6
            No. Adding an "optionCriteria" field does not solve the problem. No other FormItem in SmartGWT requires optionCriteria fields to be present in the DataSource unless the dropExtraFields is true so I am not really sure what this answer is all about. Have you tried to run the test case?

            Comment


              #7
              You will need a field declaration for various reasons, including conveying type. Also, dropExtraFields is unrelated (it applies to server>client transmission of records, whereas we're talking about client>server transmission of criteria).

              However the actual problem in this case is that MultiComboBoxItem requires you to specify optionCriteria via setComboBoxProperties() - this is covered right in the class doc at the top. While documented, this does seem like an unnecessary extra step, and we're looking at refining this. In the meantime, just follow the documented approach.

              Comment


                #8
                Okay so I changed the Test Case to this, but now the MultiComboBoxItem doesn't even fetch anything not even when I try to open the picklist.
                Code:
                final VLayout mainLayout = new VLayout();
                
                DynamicForm form = new DynamicForm();
                form.setWidth(400);
                
                DataSource optionDataSource = DataSource.get("optionDatasourceTest");
                
                ComboBoxItem comboBoxProperties = new ComboBoxItem();
                comboBoxProperties.setPickListFilterCriteriaFunction(new FormItemCriteriaFunction() {
                    
                    @Override
                    public Criteria getCriteria(FormItemFunctionContext itemContext) {
                        return new Criteria("optionCriteria", "This should also be sent on autoFetchData.");
                    }
                });
                
                MultiComboBoxItem item = new MultiComboBoxItem("comboBox");
                item.setOptionDataSource(optionDataSource);
                item.setDisplayField("display");
                item.setValueField("value");
                item.setAutoFetchData(true);
                item.setComboBoxProperties(comboBoxProperties);
                item.setValue(new Integer[] { 4 });  // setting a non existing value to trigger missingValueFetch
                
                form.setItems(item);
                
                mainLayout.addMember(form);
                
                mainLayout.draw();
                Same result with:
                Code:
                final VLayout mainLayout = new VLayout();
                
                DynamicForm form = new DynamicForm();
                form.setWidth(400);
                
                DataSource optionDataSource = DataSource.get("optionDatasourceTest");
                
                ComboBoxItem comboBoxProperties = new ComboBoxItem();
                comboBoxProperties.setOptionCriteria(new Criteria("optionCriteria", "This should also be sent on autoFetchData."));
                
                MultiComboBoxItem item = new MultiComboBoxItem("comboBox");
                item.setOptionDataSource(optionDataSource);
                item.setDisplayField("display");
                item.setValueField("value");
                item.setAutoFetchData(true);
                item.setComboBoxProperties(comboBoxProperties);
                item.setValue(new Integer[] { 4 });  // setting a non existing value to trigger missingValueFetch
                
                form.setItems(item);
                
                mainLayout.addMember(form);
                
                mainLayout.draw();
                What am I missing?

                Comment


                  #9
                  We have tested your test case, and it worked as expected with the latest code of 10.0. Please try upgrading to the latest build of 10.0 or 10.1 and test again.

                  Regards
                  Isomorphic Software

                  Comment


                    #10
                    To clarify, the first version of your code would be expected to break the MultiComboBoxItem, because your FormItemCriterionFunction completely ignores the user's typed-in search string. But the second version should work, and does in our testing.

                    Comment

                    Working...
                    X