Announcement

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

    Problem with ComboBox/ValueMap from DataBase

    Hi, i'm using GWT2.4.0, and while populating a Combobox with data from our database via RPC, i use this datasource:


    Code:
        @Override
        public List<DataSourceField> getDataSourceFields() {
           List<DataSourceField> fields = new ArrayList<DataSourceField>();
    
            DataSourceSequenceField idField = new DataSourceSequenceField(ID_FIELD);
            idField.setHidden(true);
            idField.setPrimaryKey(true);
            fields.add(idField);
    
            DataSourceTextField nameField = new DataSourceTextField(ROL_NAME, "Name");
            fields.add(nameField);
    
            final DataSourceEnumField permissionList = new DataSourceEnumField(PERMISSIONS, "Permissions");
            SelectItem selectItem = new SelectItem();
            selectItem.setMultiple(Boolean.TRUE);
            selectItem.setMultipleAppearance(MultipleAppearance.PICKLIST);
            permissionList.setEditorType(selectItem);
            RoleHelperAsync rolesService = (RoleHelperAsync) GWT.create(RoleHelper.class);
            rolesService.getPermissionsMap(new AsyncCallback<Map<String, String>>() {
    
                @Override
                public void onFailure(Throwable caught) {
                    SC.say(messages.showException(caught.getMessage()));
               }
    
                @Override
                public void onSuccess(Map<String, String> result) {
                    permissionList.setValueMap(result);
                }
            });
            fields.add(permissionList);
        }
    
        @Override
        public void copyValues(ListGridRecord from, Roles to) {
            to.setRolId(from.getAttributeAsInt(ID_FIELD));
            to.setRolName(from.getAttributeAsString(ROL_NAME));
            to.setPermissionsMap(from.getAttributeAsMap(PERMISSIONS));
        }
    
        @Override
        public void copyValues(Roles from, ListGridRecord to) {
            to.setAttribute(ID_FIELD, from.getRolId());
            to.setAttribute(ROL_NAME, from.getRolName());
            to.setAttribute(PERMISSIONS, from.getPermissionsMap());
        }
    In the Widget i have:
    Code:
            final ListGrid listGrid = new ListGrid();
            final DynamicForm editForm = new DynamicForm();
            DataSource dataSource = RoleDataSource.getInstance();
            IButton btnRemove = new IButton("Remove");
            IButton btnAdd = new IButton("Add row");
            IButton saveButton = new IButton("Save");
    
            listGrid.setWidth(600);
            listGrid.setHeight(300);
    
            listGrid.setDataSource(dataSource);
            editForm.setDataSource(dataSource);
    
            listGrid.setSelectionType(SelectionStyle.MULTIPLE);
            listGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
    
            listGrid.setAutoFetchData(true);
    
            listGrid.fetchData();
    
            listGrid.addRecordClickHandler(new RecordClickHandler() {
    
                @Override
                public void onRecordClick(RecordClickEvent event) {
                    editForm.clearErrors(true);
                    listGrid.selectRecord(event.getRecord());
                    editForm.editRecord(event.getRecord());
                }
            });
    
            //btnRemove ClickHandler
            btnRemove.addClickHandler(new ClickHandler() {
    
                @Override
                public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
    
                    try {
                        //get the currently selected records
                        final ListGridRecord[] selectedRecords;
                        selectedRecords = listGrid.getSelectedRecords();
    
                        if (selectedRecords.length > 0) {
    
                            SC.ask(messages.confirmDelete(), new BooleanCallback() {
    
                                @Override
                                public void execute(Boolean value) {
                                    if (value != null && value) {
                                        listGrid.removeSelectedData();
                                        SC.say(messages.recordDeleted());
                                    }
                                }
                            });
                        } else {
                            SC.say(messages.recordNeeded());
                        }
                    } catch (Exception ex) {
                        SC.say(messages.showException(ex.getMessage()));
                    }
                }
            });
    
            //newCompanyButton ClickHandler
            btnAdd.addClickHandler(new ClickHandler() {
    
                @Override
                public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
                    try {
                        editForm.editNewRecord();
                        editForm.focusInItem("rol_name");
                    } catch (Exception ex) {
                        SC.say(messages.showException(ex.getMessage()));
                    }
                }
            });
    
            //newCompanyButton ClickHandler
            saveButton.addClickHandler(new ClickHandler() {
    
                @Override
                public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
                    try {
                        editForm.saveData();
                        listGrid.refreshFields();
                        SC.say(messages.recordUpdated());
                    } catch (Exception ex) {
                        SC.say(messages.showException(ex.getMessage()));
                    }
                }
            });
    
    
            VLayout layoutMainRight = new VLayout();
            layoutMainRight.addMember(listGrid);
            HLayout toolLayout = new HLayout();
            VLayout buttonsLayout = new VLayout();
            toolLayout.addMember(editForm);
            buttonsLayout.addMember(btnRemove);
            buttonsLayout.addMember(btnAdd);
            buttonsLayout.addMember(saveButton);
            toolLayout.addMember(buttonsLayout);
            layoutMainRight.addMember(toolLayout);
    And finally the DB POJO has:

    Code:
        public Map<String, String> getPermissionsMap() {
            Map<String, String> permMap = new HashMap<String, String>();
            for(int i = 0; i < permissionsList.size(); i++) {
                permMap.put(permissionsList.get(i).getPerId().toString(), permissionsList.get(i).getPerModule() + " - " + permissionsList.get(i).getPerName());
            }
            return permMap;
        }
    
        public void setPermissionsMap(Map<String, String> permissionsMap) {
            if(permissionsList != null) {
                permissionsList.clear();
            }
            for(Map.Entry<String,String> entry : permissionsMap.entrySet()) {
                permissionsList.add(new Permissions(new Integer(entry.getKey())));
            }
        }
    While, this is suppose to work, as you can see in the image the values are not loading right, it only says [object Object]

    Where are using the GenericGwtRpcDataSource as explained in http://forums.smartclient.com/showthread.php?t=10850

    Any idea would be welcomed
    Attached Files

    #2
    Hello?? Isomorphic?? anyone??

    Any kind of comment would be good now.

    Comment


      #3
      Hello list, someone interested in solving our problem (for a fee) please get in contact with me mauricio.camayo at edgeconsultants dot com

      Comment


        #4
        Somehow you are providing objects instead of atomic values to the ComboBoxItem.

        See the FAQ - for a long list of reasons we recommend against GWT-RPC.

        Comment


          #5
          Hello, thanks for the response.

          I'm using setValueMap, and what i'm providing is a Map<String, String>, and when loading the DynamicForm i'm copying a Map<String, String> too.

          Of course, as this is a multiple selection combobox, i have to pass a map, and not a single item, and there's the problem. I have tested with single items, and it works, problem is when using multiple selection

          Comment


            #6
            Hi macaco,

            i am using two select items with datasource, where the values are populated from the db and one selectItem is dependent on others selection. I posted my problem in http://forums.smartclient.com/showthread.php?t=19838

            As i was browsing for my problem, i gone through your thread. If you faced the same issue, please let me know.
            Last edited by yathihv; 30 Nov 2011, 09:42.

            Comment


              #7
              If you think there's a bug here, please show a minimal, standalone test case that demonstrates the problem. The standalone test case must not use GWT-RPC (unnecessary - test case would not be minimal).

              Along with the test case, be sure to mention all the required version information omitted from your posts so far.

              Comment

              Working...
              X