Announcement

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

    Problem with getPickListFilterCriteria() after upgrading to smartGWTPro 2.3

    SmartGWT version: 2.3 Pro
    Browser: Firefox (but appears to be non-browser specific, also occurs with Safari and IE).


    I recently upgraded one of our existing applications from SmartGWT Pro 2.1 to SmartGWT Pro 2.3. This went pretty smoothly, except for one issues that appears to have cropped up. This was definitely working in 2.1 but no longer works in 2.3 - I'm not sure why.

    I have a number of comboBoxItems that are databound and dependent selects (similar to the example for Databound Depedent Selects from the showcase). All of them have the same problem; but I'll use one specific example. I have 3 comboBoxItems: country, state and location. They are supposed to be dependent selects - picking a country is supposed to filter the state and location comboBoxItems, picking a state is supposed to filter the location comboBoxItem. In other words: if I select Country= United States and State = Georgia, I should only get locations that are in the US and in the state Georgia. Pretty straightforward. In addition, if the user starts typing in one of the dropdowns, it's supposed to "auto-complete" by limiting options, so if I type "Uni" in the Country dropdown, it's supposed to show countries that start with "Uni" - in this case, the United Kingdom and the United States.

    I implemented this as follows:

    Creation of dropdowns:

    Code:
    country = new CountryComboBoxItem(DIDField.COUNTRY.getName());
    
    		country.setTitle(DIDField.COUNTRY.getDisplayTitle());
    		country.setWidth(225);
    		country.setValueField(CountryField.COUNTRY_ID.getName());
    		country.setDisplayField(CountryField.COUNTRY_NAME.getName());
    		country.setOptionDataSource(countryDS);
    
    		
    		
    		ListGridField countryFlag = new ListGridField(CountryField.COUNTRY_CODE.getName(), "Flag", 30);
    		countryFlag.setType(ListGridFieldType.IMAGE);
    		countryFlag.setImageURLPrefix("flags/16/");  
    		countryFlag.setImageURLSuffix(".png");
    		
    		ListGridField countryName = new ListGridField(CountryField.COUNTRY_NAME.getName(), CountryField.COUNTRY_NAME.getDisplayTitle());
    		country.setPickListFields(countryFlag, countryName);
    		
    	
    		
    		state = new StateComboBoxItem(DIDField.STATE.getName());
    		state.setTitle(DIDField.STATE.getDisplayTitle());
    		state.setWidth(225);
    		state.setValueField(StateField.STATE_ID.getName());
    		state.setDisplayField(StateField.STATE_NAME.getName());
    		state.setOptionDataSource(stateDS);
    		
    		
    		ListGridField stateCountryFlag = new ListGridField(StateField.COUNTRY_CODE.getName(), "Flag", 30);
    		stateCountryFlag.setType(ListGridFieldType.IMAGE);
    		stateCountryFlag.setImageURLPrefix("flags/16/");
    		stateCountryFlag.setImageURLSuffix(".png");
    		ListGridField stateName = new ListGridField(StateField.STATE_NAME.getName(), StateField.STATE_NAME.getDisplayTitle());
    		state.setPickListFields(stateName, stateCountryFlag);
    		
    		
    		location = new LocationComboBoxItem(DIDField.LOCATION.getName());
    		location.setTitle(DIDField.LOCATION.getDisplayTitle());
    		location.setWidth(225);
    		location.setValueField(LocationField.LOCATION_ID.getName());
    		location.setDisplayField(LocationField.LOCATION_NAME.getName());
    		location.setOptionDataSource(locationDS);
    		
    		
    		ListGridField locationCountryFlag = new ListGridField(LocationField.COUNTRY_CODE.getName(), "Flag", 30);
    		ListGridField locationStateName = new ListGridField(LocationField.STATE_CODE.getName(), LocationField.STATE_CODE.getDisplayTitle(), 30);
    		locationCountryFlag.setType(ListGridFieldType.IMAGE);
    		locationCountryFlag.setImageURLPrefix("flags/16/");
    		locationCountryFlag.setImageURLSuffix(".png");
    		ListGridField locationName = new ListGridField(LocationField.LOCATION_NAME.getName(), LocationField.LOCATION_NAME.getDisplayTitle());
    		location.setPickListFields(locationName, locationStateName, locationCountryFlag);
    inner classes for dropdowns:

    Code:
    public class CountryComboBoxItem extends IntComboBoxItem
    	{
    		public CountryComboBoxItem(String name)
    		{
    			super(name);
    
    		}
    		
    		@Override
    		public Criteria getPickListFilterCriteria()
    		{
    			
    				Criteria criteria = new Criteria();
    				
    				if(getValue()!= null && getValue() instanceof String)
    				{
    					criteria.addCriteria(CountryField.COUNTRY_NAME.getName(), (String)getValue());
    				}
    				
    				criteria.addCriteria(CountryField.FILTERED.getName(), true);
    				
    				return criteria;
    			
    		}
    		
    	}
    	
    	public class StateComboBoxItem extends IntComboBoxItem
    	{
    		public StateComboBoxItem(String name)
    		{
    			super(name);
    		}
    		
    		@Override
    		public Criteria getPickListFilterCriteria()
    		{
    			Criteria criteria =  new Criteria();
    			
    			if(country.getSelectedRecord() != null)
    			{
    				String countryId = country.getSelectedRecord().getAttribute(CountryField.COUNTRY_ID.getName());
    				criteria.addCriteria(DirectoryListingField.COUNTRY.getName(), countryId);
    			}
    			
    			if(getValue()!= null && getValue() instanceof String)
    			{
    				criteria.addCriteria(StateField.STATE_NAME.getName(), (String)getValue());
    			}
    			
    			criteria.addCriteria(CountryField.FILTERED.getName(), true);
    				
    			return criteria;
    		}
    	
    	}
    	
    	public class LocationComboBoxItem extends IntComboBoxItem
    	{
    		public LocationComboBoxItem(String name)
    		{
    			super(name);
    		}
    		
    		@Override
    		public Criteria getPickListFilterCriteria()
    		{
    			Criteria criteria = new Criteria();
    			
    			if(country.getSelectedRecord() != null)
    			{
    				String countryId = country.getSelectedRecord().getAttribute(CountryField.COUNTRY_ID.getName());
    				criteria.addCriteria(DirectoryListingField.COUNTRY.getName(), countryId);
    			}
    			
    			if(state.getSelectedRecord() != null)
    			{
    				String stateId = state.getSelectedRecord().getAttribute(StateField.STATE_ID.getName());
    				criteria.addCriteria(DirectoryListingField.STATE.getName(), stateId);
    			}
    			
    			if(getValue()!= null && getValue() instanceof String)
    			{
    					criteria.addCriteria(LocationField.LOCATION_NAME.getName(), (String)getValue());	
    			}
    			
    			criteria.addCriteria(CountryField.FILTERED.getName(), true);
    				
    			return criteria;
    		}
    		
    		
    	}
    EventHandling:

    Code:
    	HandlerRegistration countryPickerAboutToChangeReg = country.addChangeHandler(new ChangeHandler(){
    
    				@Override
    				public void onChange(ChangeEvent event) {
    					state.clearValue();
    					location.clearValue();
    					
    				}
    				
    				
    			});
    			
    			
    			HandlerRegistration countryPickerReg = country.addChangedHandler(new ChangedHandler()
    			{
    
    				@Override
    				public void onChanged(ChangedEvent event) {
    					
    						state.fetchData();
    						location.fetchData();
    
    				}
    				
    			});
    			
    			HandlerRegistration statePickerChangeRegAboutToChangeReg = state.addChangeHandler(new ChangeHandler(){
    
    				@Override
    				public void onChange(ChangeEvent event) {
    					location.clearValue();
    					
    				}
    				
    				
    			});
    			
    			HandlerRegistration statePickerReg = state.addChangedHandler(new ChangedHandler(){
    				
    				@Override
    				public void onChanged(ChangedEvent event)
    				{
    					location.fetchData();
    				
    				}
    				
    			});
    			
    			HandlerRegistration locationPickerReg = location.addChangedHandler(new ChangedHandler()
    			{
    				@Override
    				public void onChanged(ChangedEvent event)
    				{
    					location.fetchData();
    				}
    			});
    In 2.1, this worked as expected. In 2.3; it only works the first time a selection is made, on subsequent selections the pickListCriteria don't seem to get updated, but instead it submits the criteria for the first selection.

    What this means is this: I pick the state "Delaware", the location box updates and shows locations for Delaware. I now change the state to Florida, the server actually still gets asked for State=Delaware and the LocationBox still shows locations for Delaware.

    I can see from server logs that the request IS being made from the RPCManager, but the value for state isn't being changed. No idea why.

    Server log for first Delaware request:

    14:52:56,936 DEBUG XML:406 - Parsed XML from (in memory stream): 1ms
    14:52:56,938 DEBUG RPCManager:406 - Processing 1 requests.
    14:52:56,938 DEBUG RPCManager:406 - Request #1 (DSRequest) payload: {
    criteria:{
    state:"22",
    filtered:true
    },
    operationConfig:{
    dataSource:"location",
    operationType:"fetch",
    textMatchStyle:"startsWith"
    },
    startRow:0,
    endRow:75,
    componentId:"isc_PickListMenu_1",
    appID:"builtinApplication",
    operation:"location_fetch",
    oldValues:{
    state:"22",
    filtered:true
    }
    }
    Request for second "Floriday" request:

    14:53:32,376 DEBUG XML:406 - Parsed XML from (in memory stream): 1ms
    14:53:32,379 DEBUG RPCManager:406 - Processing 1 requests.
    14:53:32,379 DEBUG RPCManager:406 - Request #1 (DSRequest) payload: {
    criteria:{
    state:"22",
    filtered:true
    },
    operationConfig:{
    dataSource:"location",
    operationType:"fetch",
    textMatchStyle:"startsWith"
    },
    startRow:0,
    endRow:75,
    componentId:"isc_PickListMenu_1",
    appID:"builtinApplication",
    operation:"location_fetch",
    oldValues:{
    state:"22",
    filtered:true
    }
    }
    You can see that the id for state isn't changing.

    Any idea why, guys?

    #2
    This may be why. I modified the client code and added some extra debug statements:

    Code:
    public class LocationComboBoxItem extends IntComboBoxItem
    	{
    		public LocationComboBoxItem(String name)
    		{
    			super(name);
    		}
    		
    		@Override
    		public Criteria getPickListFilterCriteria()
    		{
    			Log.debug("getting Location criteria");
    			Criteria criteria = new Criteria();
    			
    			if(country.getSelectedRecord() != null)
    			{
    				String countryId = country.getSelectedRecord().getAttribute(CountryField.COUNTRY_ID.getName());
    				criteria.addCriteria(DirectoryListingField.COUNTRY.getName(), countryId);
    			}
    			
    			if(state.getSelectedRecord() != null)
    			{
    				String stateId = state.getSelectedRecord().getAttribute(StateField.STATE_ID.getName());
    				Log.debug("State Id: " + stateId);
    				Log.debug("State value: " + state.getValue());
    				criteria.addCriteria(DirectoryListingField.STATE.getName(), stateId);
    			}
    			
    			if(getValue()!= null && getValue() instanceof String)
    			{
    					criteria.addCriteria(LocationField.LOCATION_NAME.getName(), (String)getValue());	
    			}
    			
    			criteria.addCriteria(CountryField.FILTERED.getName(), true);
    				
    			return criteria;
    		}
    		
    		
    	}
    From the output, I can see that the value of the comboBoxItem is actually changing as I make different selections; but the selectedRecord isn't - it remains 22 (the id for Delaware).

    Comment


      #3
      And actually - you can tell from the interface. If you look at this screenshot:

      http://yfrog.com/mgcomboboxitemproblemin23p

      I first selected the state Delaware. I then selected Arkansas. While the comboBoxItem itself is correctly showing itself Arkansas, the highlighted options in the dropdown remains on Delaware. This remains true, no matter what state I pick.

      PS: I blurred out parts of the interface to protect our customers.

      Comment


        #4
        Actually, now that I think about it... isn't this the same issues as this thread?

        http://forums.smartclient.com/showthread.php?t=12146

        At the time in 2.1, the script that Isomorphic posted at the end of the thread fixed the issue. When I upgraded to 2.3, that script threw a nasty javascript error; so I removed it, but it seems the original error is now back; i.e. the picklist in selectItems and comboBoxItem is caching it's local result set. I had assumed that a fix for this had made it's way in 2.2 (and hence 2.3) and I wouldn't need the script anymore anyway, but maybe it was missed somehow?

        Comment


          #5
          Must be a different issue - I added the script back in and modified the build date, but the problem is still happening. Well, guess I'll wait and see what the Isomorphic guys say... :)

          Comment


            #6
            Apparently, I have the same problem as these people found in these two threads:

            http://forums.smartclient.com/showthread.php?t=10473&highlight=getSelectedRecord

            http://forums.smartclient.com/showthread.php?t=11439&highlight=getSelectedRecord

            Definitely a bug in the underlying API. Tried the suggested fix in the last thread; i.e. overwriting the getSelectedRecord() method with:

            Code:
             final ComboBoxItem editor = new ComboBoxItem() {
                        public native ListGridRecord getSelectedRecord() /*-{
                	    
                	    var self = this.@com.smartgwt.client.core.DataClass::getJsObj()();
                	    var ret = self.pickList.getSelectedRecord();   	    
                	    if(ret == null || ret === undefined) return null;
                	    var retVal = @com.smartgwt.client.core.RefDataClass::getRef(Lcom/google/gwt/core/client/JavaScriptObject;)(ret);
                	    if(retVal == null) {
                	        retVal = @com.smartgwt.client.widgets.grid.ListGridRecord::new(Lcom/google/gwt/core/client/JavaScriptObject;)(ret);
                	    }
                	    return retVal;
                	}-*/;
            But that gives me an error saying self.pickList is undefined.

            Any chance someone from SmartGWT could fix this? It's obvious a number of people are having the same problem and in addition, the interface is actually showing misleading information (i.e. the wrong option being highlighted in the dropdown).

            Comment


              #7
              There was indeed a bug in the underlying API. We've now fixed this - the fix should show up in the next nightly build
              Let us know if you continue to see it after this

              Thanks

              Comment


                #8
                Will do, thanks Isomorphic!

                Comment

                Working...
                X