Announcement

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

    Set Selected Values for SelectItem/ComboBox

    SmartClient Version: v8.2p_2012-05-24/PowerEdition Deployment (built 2012-05-24)

    In another thread (http://forums.smartclient.com/showthread.php?t=21628) I asked how to set the selected index/value of a combobox/selectitem with an optionsDataSource.

    I have a similar use-case, but this time with a ComboBoxItem and a SelectItem that do not have an optionsDatasource.

    When a user opens a form, several criteria affect the way that the form is presented to a user. For example, if I choose option "a" the form should appear with two values pre-selected in the select/combobox mentioned above.

    Setting these values is proving to be challenging. I can use setDefaultValue("someValue"), but that does not actually select the value, so when the form is validated, those two items are considered invalid, even if they have those defaultValues displayed.

    What can I do to set the values effectively here?

    #2
    Is there some reason you don't want to call either formItem.setValue() or DynamicForm.setValue() / setValues()?

    Comment


      #3
      I'm calling formItem.setValue(), for example, the SelectItem is called siCompressionType. Calling siCompressionType.setDefaultValue(H264) doesn't work. I understand that I'm supposed to pass a pk for siCompressionType.setValue(), however, I don't know how, using the datasources to get that primary key.

      Comment


        #4
        If for some reason you have a display value and not the stored value, you can call DataSource.fetchData() passing the display value as Criteria to retrieve the (only) matching Record, and the PK from that.

        Comment


          #5
          I don't think we are understanding each other here.

          I'll try again. I need to be able to set the selected value of a combobox item and a select item. I don't know the primary key, because I'm using a datasource to populate a form. When the form is instantiated, it's told to editNewRecord(partiallyCompleteRecord).

          Because of the way the datasource is set up, I really have no way to get the primary key for the value that needs to be selected in the Combo/Select.

          Following your previous advice for dynamicForm does not work either.

          Code:
          dfStreamData.setValue("compressionMode",GSUI.getProperties().get("defaultArchivedSubviewCompression").toString());
          As you see, I'm setting the compression mode based on a default. This value most definitely maps to an enum that would be used in the persisted data for this table.

          Comment


            #6
            Sorry, we're not following the problem, and your code snippet seems unrelated to our advice.

            Either you have a value that uniquely identifies the entry in the optionDataSource that you want to have as the initial value, or you don't. If you don't, then you have an information problem, not an API problem, and we can't help.

            If you do have a value that uniquely identifies an entry in the optionDataSource, then calling DataSource.fetchData() should allow you to retrieve the unique matching Record from the optionDataSource, which will have the PK (or whatever value is stored as the valueField for the optionDataSource).

            Comment


              #7
              As I mentioned, I am not using an options datasource. This should not be this complicated.

              I have a similar use-case, but this time with a ComboBoxItem and a SelectItem that do not have an optionsDatasource.

              Comment


                #8
                So if you do not have an optionDataSource, do you have a valueMap? If so then are you asking how to get the key for a value from a Java Map?

                Comment


                  #9
                  The details are in the original question. I don't know how to explain it any clearer. Forget it.

                  Comment


                    #10
                    Maybe we're being dense, but, ComboBox and SelectItem have exactly two ways of providing the list of values: valueMap and optionDataSource. We explained how to get from a displayed value to a stored value in both scenarios.

                    And again, setValue() (and not setDefaultValue()) is what you should call.

                    Comment


                      #11
                      Maybe this will help: setValue() takes the value to store, period. In the case of a FormItem that has an optionDataSource, this is the PK (or really any unique field as specified by valueField). But in general, it's just the stored value. When there's a valueMap, this means any key from the Map.

                      Comment

                      Working...
                      X