Announcement

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

    Grid-Form binding with OptionDataSource

    I try to use grid-form editor with rpc-datasource. The grid has address objects. The form has detail fileds of address and one field is ComboBoxItem with OptionDataSource (address-purpose objects).

    But I don't know how to change values in ComboBoxItem. If I select record in grid, new row with purposeId add to comboBox, instead select one of item in comboBox.

    DataSource of Address object:
    Code:
    public AddressDS(String id) {
    
            setID(id);
    
            DataSourceIntegerField idDF = new DataSourceIntegerField("id");
            idDF.setPrimaryKey(true);
            idDF.setHidden(true);
            addField(idDF);
    
            DataSourceTextField nameDF = new DataSourceTextField("name", "Name");
            addField(nameDF);
    
            DataSourceTextField descriptionDF = new DataSourceTextField("description", "Description");
            addField(descriptionDF);
    
            DataSourceIntegerField purposeId = new DataSourceIntegerField("purposeId");
            purposeId.setHidden(true);
            addField(purposeId);
    
            DataSourceTextField purposeName = new DataSourceTextField("purposeName", "Purpose");
            addField(purposeName);
    }
    DataSource of AddressPurpose object:
    Code:
        public AddressPurposeDS(String id) {
    
            setID(id);
    
            DataSourceIntegerField purposeId = new DataSourceIntegerField("purposeId");
            purposeId .setPrimaryKey(true);
            addField(purposeId);
    
            DataSourceTextField purposeName = new DataSourceTextField("purposeName");
            addField(purposeName);
        }
    Source code of the grid-form panel:
    Code:
            final AddressDS ds = AddressDS.getInstance();
    
            final ListGrid grid = new ListGrid();
            grid.setDataSource(ds);
            grid.setAlternateRecordStyles(true);
            grid.setShowAllRecords(true);
            grid.setAutoFetchData(true);
            grid.setCanEdit(false);
            grid.setCanResizeFields(true);
    
            final DynamicForm form = new DynamicForm();
            form.setDataSource(ds);
    
            final ComboBoxItem purpose = new ComboBoxItem();
    purpose.setOptionDataSource(AddressPurposeDS.getInstance());
            purpose.setName("purposeId");
            purpose.setValueField("purposeId");
            purpose.setDisplayField("purposeName");
            purpose.setAutoFetchData(true);
    
            TextItem name = new TextItem("name");
    
            form.setFields(purpose, name);
    
            grid.addRecordDoubleClickHandler(new RecordDoubleClickHandler() {
                public void onRecordDoubleClick(RecordDoubleClickEvent event) {
                    form.clearErrors(true);                
                    form.editRecord(event.getRecord());
                }
            });

    #2
    Could you try explaining in more detail what exactly you were expecting and what's happening instead? Thanks.

    Comment


      #3
      Thanks for your response.

      I expect that purpose field type ComboBoxItem shall choose item depending the address chosen.

      But now items are not chosen, just add identifier of purpose object to the first position of combo-box.

      In other words, field in grid record is not linked to combo-box field in form.

      Could you explain me, how to link that fields?

      Comment


        #4
        It looks like you've linked them correctly, but your AddressPurposeDS may not be functioning correctly. Try looking in the Developer Console for warnings and the RPC tab for attempted fetches, and/or using the AddressPurposeDS directly to test it out.

        Comment


          #5
          Thanks.
          purposeId was Long, and data-field in data-source was DataSourceIntegerField.

          Comment

          Working...
          X