Announcement

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

    how to refresh databound UI components (SelectItem), once data has changed

    Hi,

    i am having hard time figuring out, how to refresh the databound UI components. Well, i will try to explain my problem in detail:

    I have a datasource which has many fields; couple of them are datasourceTextFields with valueMaps. Now this datasource is bound to a ListGrid as well as a DynamicForm. In DynamicForm, the datasourceTextfields with valueMaps correspond to SelectItem(ComboBox) UI component.
    Now sometime during the execution of the program, the valueMaps for the datasourceFields is updated (changed).

    How do i propogate these changes to the corresponding UI components i.e. in my case to ListGrid and DynamicForm's ComboBox, so that the databound UI-components show the updated entries in the valueMap?

    #2
    If you use an optionDataSource instead of a static valueMap (if this makes sense for you) and the modifications to the valueMaps are because of "update" and "add" operations on that DataSource, the valueMap will be updated automatically. If not, call setValueMap() to change a valueMap.

    Comment


      #3
      Hi Isomorphic,

      thanks much for your quick response.

      As suggested by you "call setValueMap() to change a valueMap", i am doing it precisely like that. ValueMap entries are actually are actually updated (changed). But my problem is that the corresponding bound UI-components, which are the DynamicForm's ComboBox and the ListGridField are still rendered with the old valueMap entries. How can i make these UI-component refresh with their underlying datasource/ValueMap?

      Regards

      Comment


        #4
        Hi,

        In the following is the sample code:

        Code:
        package de.fit.sample.client;
        
        import java.util.LinkedHashMap;
        import com.google.gwt.core.client.EntryPoint;
        import com.google.gwt.user.client.Cookies;
        import com.smartgwt.client.data.DataSource;
        import com.smartgwt.client.data.fields.DataSourceIntegerField;
        import com.smartgwt.client.data.fields.DataSourceTextField;
        import com.smartgwt.client.widgets.IButton;
        import com.smartgwt.client.widgets.form.DynamicForm;
        import com.smartgwt.client.widgets.grid.ListGrid;
        import com.smartgwt.client.widgets.layout.VLayout;
        
        /**
         * Entry point classes define <code>onModuleLoad()</code>.
         */
        public class Sample1 implements EntryPoint {
        	
        	DataSourceTextField departmentField;
        	
        	public void onModuleLoad() {
        
        		Cookies.setCookie("skin", "SilverWave");
        		
        		DataSource clientDS = getClientDS();
        		
        		ListGrid grid = new ListGrid();
        		grid.setWidth(300);
                grid.setHeight(200);
        		grid.setDataSource(clientDS);
        		
        		DynamicForm form = new DynamicForm();
        		form.setDataSource(clientDS);
        		
        		IButton updateButton = new IButton("update ValueMap");
        		updateButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
        
                	public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
                		updateValueMap();
                	}
                });
        		
        		VLayout mainLayout = new VLayout(10);
        		
        		mainLayout.addMember(grid);
        		mainLayout.addMember(form);
        		mainLayout.addMember(updateButton);
        		
        		mainLayout.draw();
        	}
        	
        	public DataSource getClientDS() {
        		DataSource ds = new DataSource();
        		
        		DataSourceIntegerField pkField = new DataSourceIntegerField("pid");
        		pkField.setHidden(true);
        		pkField.setPrimaryKey(true);
        		
        		DataSourceTextField clientIDField = new DataSourceTextField("clientID", "Client-ID");
        		clientIDField.setRequired(true);
        		
        		DataSourceTextField clientNameField = new DataSourceTextField("clientName", "Client-Name");
        		clientNameField.setRequired(true);
        		
        		departmentField = new DataSourceTextField("department", "Department");
        		departmentField.setRequired(true);
        		LinkedHashMap<String, String> departmentMap = new LinkedHashMap<String, String>();
        		departmentMap.put("1", "HR");
        		departmentMap.put("2", "Sales");		
        		departmentField.setValueMap(departmentMap);
        		
        		ds.setFields(pkField,clientIDField,clientNameField,departmentField);
        
        		ds.setClientOnly(true);
        		
        		return ds;
        	}
        	
        	public void updateValueMap() {
        		LinkedHashMap<String, String> departmentMap = new LinkedHashMap<String, String>();
        		departmentMap.put("1", "HR");
        		departmentMap.put("2", "Sales");
        		departmentMap.put("3", "Finance");
        		departmentField.setValueMap(departmentMap);
        	}
        }
        Once youe update the ValueMap by clicking the button "updateValueMap", the combo in the form still contains 2 values; HR and sales.

        What i need to do in order to update the visual components with the updated ValueMap in DataSource?

        Regards

        Comment


          #5
          The DataSourceFields can be treated as value objects that are used for initial configuration of the grid. After the grid has been rendered, updating these has no effect unless you reconfigure the entire grid. User ListGrid.setValueMap(field, valueMap) instead.

          Comment


            #6
            &amp; filter bar?

            Thanks, I did that, and now the selection for the rows in my ListGrid are updated, but the selection box for the filter bar on the ListGrid has fallen out of synch..

            Comment


              #7
              Originally posted by sullivan
              Thanks, I did that, and now the selection for the rows in my ListGrid are updated, but the selection box for the filter bar on the ListGrid has fallen out of synch..
              Okay, I found if I call ListGrid.refreshCell(0, 0) (in my case it happens to be in the first column) immediately after ListGrid.setValueMap(String, String[]) the selection box on the filter bar is also updated.

              Thanks!

              Comment


                #8
                Originally posted by sullivan
                Okay, I found if I call ListGrid.refreshCell(0, 0) (in my case it happens to be in the first column) immediately after ListGrid.setValueMap(String, String[]) the selection box on the filter bar is also updated.

                Thanks!
                Oops! Okay, I thought that worked, but I am unable to reproduce this success, even when I go back to the checkin I made right after I made this comment.

                So I am still stuck - the pulldown in the filter bar does not get updated when I call ListGrid.setValueMap(String, String[])

                Comment


                  #9
                  Try create the event responsable for update before "setEditorType".

                  I had the same case some days ago, like code below, but I solved my problem. I just inverted 1 <=> 2


                  2) dateBurnItem.addChangeHandler(new ChangeHandler(){
                  @Override
                  public void onChange(ChangeEvent event) {
                  Date dateBurn = (Date)event.getValue();

                  Questionario1.this.idForm.setValue("idade", df.getOld(new Date(), dateBurn)+"");
                  }});


                  1) dateBurnDSField.setEditorType(dataNascItem);

                  Comment


                    #10
                    Ops, Try Every time that possible user dynamicForm.getValue("fieldName") and not " fieldItem.getValue();"

                    Comment

                    Working...
                    X