Announcement

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

    SelectItem paged item setValue

    Hello Isomorphic.

    I have a question for you. We have a selectItem with a picklist, paged, having filter. The problem we face is that we want to set some value to this item. Unfortunately this works perfectly only in case this record is already loaded into selectItem. In case picklist is on some page which does not have the record we try to set calling getSelectedRecord() returns null. This can be illustrated in showcase example MultiFieldSearchSample, changing the getViewPanel to following:
    HLayout result = new HLayout();
    DataSource supplyItemDS = ItemSupplyXmlDS.getInstance();

    final DynamicForm form = new DynamicForm();
    form.setWidth(500);
    form.setNumCols(4);

    ListGrid pickListProperties = new ListGrid();
    pickListProperties.setShowFilterEditor(true);

    ListGridField skuField = new ListGridField("SKU");
    ListGridField itemNameField = new ListGridField("itemName");

    final SelectItem filteredSelect = new SelectItem("filteredSelect");
    filteredSelect.setTitle("Item (Select)");
    filteredSelect.setOptionDataSource(supplyItemDS);
    filteredSelect.setDisplayField("SKU");
    filteredSelect.setValueField("SKU");
    filteredSelect.setPickListWidth(300);
    filteredSelect.setPickListFields(skuField, itemNameField);
    filteredSelect.setPickListProperties(pickListProperties);

    ComboBoxItem filteredCombo = new ComboBoxItem();
    filteredCombo.setTitle("Item (ComboBox)");
    filteredCombo.setAddUnknownValues(false);
    filteredCombo.setOptionDataSource(supplyItemDS);
    filteredCombo.setDisplayField("itemName");
    filteredCombo.setValueField("SKU");
    filteredCombo.setPickListWidth(300);
    filteredCombo.setFilterFields("SKU", "itemName");
    filteredCombo.setPickListFields(skuField, itemNameField);

    Button button = new Button("fill");
    button.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
    filteredSelect.setValue("32706605");
    }
    });

    Button sbutton = new Button("show");
    sbutton.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
    SC.warn(filteredSelect.getSelectedRecord().toString());
    }
    });

    form.setItems(filteredSelect, filteredCombo);
    result.addMembers(form, button, sbutton);
    return result;

    Clicking first button will set the value to the item, which looks good. Clicking on second button throws null pointer exception, because getSelectedRecord() returns null.
    Is this an expected behavior? Or is there any way we can force item to load the page with corresponding record and return it when we call getSelectedRecord?
    Thanks in advance for your support.

    Best regards,
    Iaroslav

    #2
    The SelectItem cannot synchronously provide you with a record that is not loaded of course, but if you have unique criteria for that Record, you can simply call fetchData() on the optionDataSource, providing that criteria.

    Note also the formItem.fetchMissingValues behavior, which means that the SelectItem will load the displayValue for any value you set, asynchronously as needed, and cache it. However, this does not try to load the entire Record, just the displayValue, so if you need something else from a record that's not loaded, use the fetchData() approach just explained.

    Comment


      #3
      Sorry to interrupt, but
      Note also the formItem.fetchMissingValues behavior, which means that the SelectItem will load the displayValue for any value you set, asynchronously as needed, and cache it. However, this does not try to load the entire Record, just the displayValue
      does not follow docs for FormItem.fetchMissingValues nor my personal experience with SelectItem or ComboBoxItem with optionDataSource set.
      I would say that the request with criteria pointing id is send to the server and the whole record is received.
      Thanks,
      MichalG
      Last edited by michalg; 13 Dec 2016, 01:08. Reason: Typo corrected

      Comment


        #4
        Yes, a request goes to the server to fetch the display value, as documented. It is a fetch request with criteria, which means that if you have already implemented the fetch operation, you have no additional work to support this feature.

        Were you expecting something else?

        Comment


          #5
          I am not the owner of this thread. I just want to clear that:
          However, this does not try to load the entire Record, just the displayValue
          is not true in my opinion.
          Sorry for crossposting.
          MichalG

          Comment


            #6
            As I understand this flag is true by default. But what i experience with the example I gave you is that clicking on first button does not trigger any request (I checked at dev console, it has no additional request).
            Is that expected behavior?

            Comment


              #7
              harker777: your code has a usage issue: you are taking an object that only supplies properties to be used to create a FormItem or multiple FormItems (filteredSelect) and assuming it is the same as the actual FormItem created from those properties. This is invalid. Please read the docs for dataSourceField.editorType - this explains how "properties" objects behave in general (it's linked from lots of places).

              michalg: the full record or a partial record can be retrieved, based on fetchDisplayedFieldsOnly. Note that whether this setting is true or false, it would be invalid to assume getSelectedRecord() could be called synchronously (aside from the other problems with harker777's code).

              Comment


                #8
                In my code I don't use this properties anywhere. pickListProperties is not used after being set to filteredSelect. Where do I actually assume that it is the same object?

                Comment


                  #9
                  Please read the referenced doc, then ask any remaining questions.

                  Comment


                    #10
                    I do know that properties are used as a prototype for actual list grid. Where exactly do I assume it is same object? Even if I remove filtering (don't call setPickListProperties method) the behavior stays the same. I assume it has nothing to do with my question.
                    Nevertheless, if I have a select item with picklist and I call setValue() method, is it possible to ask item to make a fetch (creating some criteria based on value I pass and displayField) call by itself? If yes, should I do smth special for this to happen? Also you tell that this can't be done synchronously, but is there a way to do it asynch?

                    Regards,
                    Iaroslav

                    Comment


                      #11
                      So again, you provide filteredSelect as FormItem properties and assume later you can simply call methods on the same object. Call getItem() to get the actual FormItem created from the properties you provided. The docs we referred you to provide a more comprehensive discussion on this.

                      We've already covered how to fetch a record asynchronously: see the first reply (post #2): call fetchData() on the optionDataSource, using the ID you already have as criteria. There is no need to involve the SelectItem at all. If you don't already have a reference to the optionDataSource, it can be retrieved by DataSource.getDataSource(id), as all DataSources can be.

                      Comment


                        #12
                        Hi Isomorphic,

                        I'm also not the OP but interested in this thread as well for educational reasons.

                        In #11 you say, "you provide filteredSelect as FormItem properties". What does that mean? Is this about the methods the OP calls on filteredSelect? This is not about filteredSelect.setPickListProperties(pickListProperties), is it?
                        Because in #10 the OP says, that the automatic fetch also does not happen when not using filteredSelect.setPickListProperties(pickListProperties).

                        Is this the same problem/topic we were talking about here?

                        Best regards
                        Blama

                        Comment


                          #13
                          We covered this:

                          [quote]So again, you provide filteredSelect as FormItem properties and assume later you can simply call methods on the same object. Call getItem() to get the actual FormItem created from the properties you provided. The docs we referred you to provide a more comprehensive discussion on this.[/url]

                          So no, it is not related to setPickListProperties. setPickListProperties provides a set of ListGrid properties, not FormItem properties, so it can't be what we're talking about above. We're talking about the properties objects passed to the setItems() call.

                          Comment


                            #14
                            Hello again, Isomorphic.

                            Another question: is it possible to populate filter of picklist? For example, we have three fields displayed in the picklist and we would like to put some value into one of the filters by default. I tried calling methods like setPickListFilterCriteriaFunction, setPickListCriteria and calling fetchData with dsrequest containing criteria but all this methods filter the item but do not populate the filters, they are remain empty. The other problem is that afterwards when some filter is entered in the item, it is added to the existing criteria. We would like it to overwrite this pickListCriteria.
                            Regarding manual fetch, it does not fully cover our problem, because we really need this record to be selected afterwards in the select item.

                            Regards,
                            Iaroslav

                            Comment

                            Working...
                            X