Announcement

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

    Update a SelectItem and getting it to re-draw

    I have a SelectItem with a valueMap in a form. The form also has a ListGrid. When the user clicks on the rows in the ListGrid, I update the valueMap. Also, when the user clicks on an item in a different list, I update the whole form.

    While the valueMap is successfully updated, the SelectItem continues to display its previous value, even though that is not one of the values in the new valueMap.

    How do I get the SelectItem to update correctly?

    SmartGWT 2.5, GWT 2.4, Firefix on Windows 7.

    TIA,

    Greg

    #2
    See the docs for ListGridField / DataSourceField.setEditorType(). The editor you provide to this method is not the same as the live editor and a setValueMap() call on it will not work.

    Comment


      #3
      I tried calling updateState (), but that just generates the following error:

      Uncaught exception escaped : com.google.gwt.core.client.JavaScriptException
      (TypeError): self.updateState is not a function
      See the Development console log for details.
      Register a GWT.setUncaughtExceptionHandler(..) for custom uncaught exception handling.

      What is the "Development console log"? Because there are no messages in my Eclipse Console.

      Comment


        #4
        Originally posted by Isomorphic
        See the docs for ListGridField / DataSourceField.setEditorType(). The editor you provide to this method is not the same as the live editor and a setValueMap() call on it will not work.
        Read it, don't understand how to use it. My code is being called from
        metadataGrid.addRecordClickHandler (new RecordClickHandler() {
        @Override
        public void onRecordClick (RecordClickEvent event)

        not from within a Form EventHandler. Also, I have no idea what I should be setting the editor type to. The same as my object?

        Comment


          #5
          If you don't understand how to conform to the rules listed in those docs, then you should show all of your code so that others can point out what's wrong. Currently you're forcing speculation :)

          Comment


            #6
            Originally posted by Isomorphic
            If you don't understand how to conform to the rules listed in those docs, then you should show all of your code so that others can point out what's wrong. Currently you're forcing speculation :)
            Creating the Dynamic form (this all works as I expect it to):
            Code:
            	locationList = new SelectItem (kLocationList, "File Locations");
            	locationLink = new LinkItem (kLocationLink);
            	
            	locationList.setEditorType (locationList);
            	initFileLocations ();
            	locationList.setDefaultToFirstOption (Boolean.TRUE);
            	locationList.addChangedHandler (new ChangedHandler() {
            		@Override
            		public void onChanged (ChangedEvent event)
            		{
            			handleSelectChange (event);
            		}
            	});
            Creating the ListGrid (this gets called, the routines get called, but no field info that I can use):
            Code:
            	metadataGrid.addRecordClickHandler (new RecordClickHandler() {
            	
            	@Override
            	public void onRecordClick (RecordClickEvent event)
            	{
            		Record	theRecord = event.getRecord ();
            		String	fileLocation = theRecord.getAttribute (kFileLocation);
            		if ((fileLocation == null) || fileLocation.isEmpty ())
            			clearFileLocations ();
            		else
            			setFileLocations (fileLocation);
            	}
            });
            Routines to update the SelectItem. The problem is that the SelectItem does not update its display. So if it is displaying a long text string, and the val


            Code:
            protected static final String	kNoSample = "No Sample Selected";
            protected static final String	kNoFiles = "No files for the Sample";
            /** Set up the locationList to indicate that no sample is selected */
            private void initFileLocations ()
            {
            	LinkedHashMap<String, String>	valueMap = new LinkedHashMap<String, String> ();
            	
            	valueMap.put (kNoSample, kNoSample);
            	locationList.setValueMap (valueMap);
            //	locationList.clearValue ();  // Would like to call this, but generates exception
            }
            	
            	
            	/**
            	 * Clear out the file location select list and link, because the selected sample has no files
            	 */
            protected void clearFileLocations ()
            {
            	LinkedHashMap<String, String>	valueMap = new LinkedHashMap<String, String> ();
            	
            	valueMap.put (kNoFiles, kNoFiles);
            	locationList.setValueMap (valueMap);
            //	locationList.clearValue ();  // Would like to call this, but generates exception
            	setLink ("");	// Clear the link
            }
            	
            	
            /**
             * Set the locationList to display the possible file locations
             * 
             * @param fileLocations	Array holding all the file locations for a single sample.  Must not be 
             * empty or null
             */
            protected void setFileLocations (String[] fileLocations)
            {
            	cleanLocations (fileLocations);
            	LinkedHashMap<String, String>	valueMap = new LinkedHashMap<String, String> ();
            	
            	for (String location : fileLocations)
            		valueMap.put (location, location);
            	
            	locationList.setValueMap (valueMap);
            	locationList.clearValue ();
            	setLink (fileLocations[0]);	// Will not be called unless have at least one item
            }

            Comment


              #7
              Your call to setEditorType() below is a no-op, or possibly has negative consequences that could create this issue. If you remove it and the issue persists, then you probably have confusion about the locationList variable, eg, you are creating two instances of the SelectItem then losing track of the one that's actually in the form.

              If you don't think that's the problem, try to create minimal code that reproduces the issue, so we can run it to see a problem.

              Comment


                #8
                Originally posted by Isomorphic
                Your call to setEditorType() below is a no-op, or possibly has negative consequences that could create this issue. If you remove it and the issue persists, then you probably have confusion about the locationList variable, eg, you are creating two instances of the SelectItem then losing track of the one that's actually in the form.

                If you don't think that's the problem, try to create minimal code that reproduces the issue, so we can run it to see a problem.
                Well, I know the setEditorType isn't my problem, because I added it in response to your first suggestion on how to solve the problem.

                I'm pretty sure that locationList is't getting double allocated, since it's allocated in the constructor, and besides, I know that the valueMap is being set, because if I click on the list the new settings are there, and the old settings are gone, OTHER than whatever setting was selected. And that hold over value goes away as soon as I select something else.

                Example:
                SelectItem is set to "foo"
                setValueMap -> "bar"
                SelectItem continues to show "foo"
                Click on SelectItem, First option is "foo", second is "bar"
                Select "bar"
                Click on SelectItem: First option is "bar", there is no second option

                I don't know if it makes a difference that the SelectItem is set to default to its first item, but it is.

                Comment


                  #9
                  Why speculate? You can completely eliminate the possibility that your code is accessing the wrong item by just using ChangeEvent.getItem() to get the item that fired the event.

                  Comment


                    #10
                    Originally posted by Isomorphic
                    Why speculate? You can completely eliminate the possibility that your code is accessing the wrong item by just using ChangeEvent.getItem() to get the item that fired the event.
                    Because I don't have a ChangeEvent where the problem occurs.

                    The user clicks in the ListGrid, changing the selected Sample. I then update the SelectItem that is part of the same DynamicForm as the ListGrid. It is this update process where the problem occurs.

                    The user clicks on a completely different list, and we change the contects of the DynamicForm (i.e. the values of all the fields). Again, I don't have a ChengeEvent here, and I most Certainly don't have a change event for my SelectItem, because the user didn't do anything to it.

                    But now that the underlying data has changed, I need to change the SelectItem. And while it acknowledges the change to its valueMap, it does NOT change the selected item.

                    How do I force it, prgramatically, to change the selected item?

                    Comment


                      #11
                      In that case, you can completely eliminate the possibility that you're interacting with the wrong object by starting with a call to dynamicForm.getItem().

                      Comment

                      Working...
                      X