Announcement

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

    ListGrid.getEditedRecord / getRecord behaviour change with 4.0p

    Hello,

    We upgraded our application from 3.1p to 4.0p (NIGHTLY-2013-08-26) and had some issues with our custom code. The culprit was a change in the logic how 4.0p version acts when calling ListGrid's getEditedRecord and getRecord in series.

    We have some code acting on edited list grid rows calling as follows:

    Code:
        Record edited = grid.getEditedRecord(row);
        Record actualRecord = grid.getRecord(row);
        ...
    Running this code on 3.1p returns the records as separate objects. After upgrading to 4.0p it seems that the first row works as expected but calling the getRecord(row) method afterwards returns the same Record object but ofcourse loses the edited attributes from the object. Our code fails as the edited variable does not hold the edited attributes anymore.

    We can easily go around this issue but we thought about asking if this is really intentional ?

    Thanks,
    Marko

    #2
    As described, that's not an intentional change and seems incorrect, but we'll need to see a test case to understand whether there's really a usage error here.

    Comment


      #3
      ListGrid.getEditedRecord / getRecord behaviour change with 4.0p

      I have the same problem after upgrading from 3.1p to 4.0p (latest nightly builds doesn't resolve the problem).
      I can replicate it with this simple example (on Chrome 33.0.1750.152): if you modify field 'Name' on row 0 and then select another record console log show right edit value after getEditedRecord method call and previous value after getRecord method call.

      Code:
      	public void onModuleLoad() {
      		
      		final ListGrid grid = new ListGrid();
      		grid.setID("simpleListGrid");
      		grid.setWidth(1200);
      		grid.setHeight(224);
      		grid.setCanEdit(true);
      		grid.setCanAutoFitFields(true);
      		grid.setValidateByCell(true);
      		grid.setAutoFetchData(true);
      		grid.setDataFetchMode(FetchMode.LOCAL);
      		grid.setDataSource(EmployeeXmlDS.getInstance());
      		grid.setSelectionType(SelectionStyle.SINGLE);
      		grid.setEditEvent(ListGridEditEvent.CLICK); 
      		grid.setAutoSaveEdits(false);
      		
      		ResultSet resultSet = new ResultSet();
      		resultSet.setUseClientSorting(false);
      		
      		grid.setDataProperties(resultSet);
      		
      		ListGridField nameField = new ListGridField("Name", 150);
      		nameField.setType(ListGridFieldType.TEXT);
      		
      		ListGridField jobField = new ListGridField("Job", 150);
      		ListGridField employeeTypeField = new ListGridField("EmployeeType", 150);
      		employeeTypeField.setCanEdit(false);
      		
      		ListGridField employeeStatusField = new ListGridField("EmployeeStatus", 200);
      		ListGridField salaryField = new ListGridField("Salary", 100);
      		ListGridField genderField = new ListGridField("Gender", 100);
      		ListGridField maritalStatusField = new ListGridField("MaritalStatus", 100);
      		
      		grid.setFields(nameField, jobField, employeeTypeField, employeeStatusField, salaryField, genderField, maritalStatusField);
      
      		grid.setEditByCell(false);
      
      		grid.addSelectionChangedHandler(new SelectionChangedHandler() {
      			
      			@Override
      			public void onSelectionChanged(SelectionEvent event) {
      				
      				Record editedRecord = grid.getEditedRecord(0);
      				
      				// here i can see the edit value into editedRecord
      				GWT.log("edit value 1 " + editedRecord.getAttributeAsString("Name"));
      				
      				Record record = grid.getRecord(0);
      				
      				// here edited record doesn't contains new edit value, but seems to be reset at previous value
      				GWT.log("edit value 2 " + editedRecord.getAttributeAsString("Name"));
      				
      			}
      		});
      		
      		grid.draw();
      		
      	}

      Comment


        #4
        That's not a bug, that's the documented and desirable behavior. Read the Grid Editing overview.

        Comment


          #5
          I still don't understand. I've set AutoSaveEdits to false in ListGrid and in the sample code the second log shows the old value, but i get it from reference to edited record.
          The javadoc of getEditedRecord method says "Returns: A copy of the record with unsaved edits included"
          but seems to exist a reference problem when i call getRecord method after getEditedRecord method call:
          Code:
          Record editedRecord = grid.getEditedRecord(0);
          				
          // here i can see the edit value into editedRecord
          GWT.log("edit value 1 " + editedRecord.getAttributeAsString("Name"));
          				
          Record record = grid.getRecord(0);
          				
          // here edited record doesn't contains new edit value, but seems to be reset at previous value
          GWT.log("edit value 2 " + editedRecord.getAttributeAsString("Name"));
          If 'Name' field original value was 'Mickey' and i edit it as 'Pluto' first log shows 'Pluto' (correctly) and second log shows 'Mickey' (incorrect, IMHO).
          For the same code using SmartGwt 3.1p log show 'Pluto' and 'Pluto'.

          Comment


            #6
            We've not been able to reproduce this issue though we've tried with 4.0p and other versions of SGWT as well as different browsers.

            Can you provide the EXACT version of SC/SGWT that you're using and a repro case - a modified showcase sample might be an easy way to do this. For example, you could modify the GridEditByRowSample which is present in the SGWT LGPL Showcase here: http://www.smartclient.com/smartgwt/...id_editing_row

            Also, does this issue show up in production or development mode?
            Last edited by Isomorphic; 27 Mar 2014, 15:06.

            Comment


              #7
              I'm using SmartGWT 4.0p 2014-02-12 nightly build.
              I can replicate this issue using the given showcase as

              Code:
              public class GridEditByRowSample implements EntryPoint {
              
              	public void onModuleLoad() {
              
              		final ListGrid countryGrid = new ListGrid();
              		countryGrid.setWidth(550);
              		countryGrid.setHeight(224);
              		countryGrid.setShowAllRecords(true);
              		countryGrid.setCellHeight(22);
              		countryGrid.setDataSource(CountryXmlDS.getInstance());
              		countryGrid.setAutoSaveEdits(false);
              		
              		ResultSet resultSet = new ResultSet();
              		resultSet.setUseClientSorting(false);
              		
              		countryGrid.setDataProperties(resultSet);
              
              		ListGridField countryCodeField = new ListGridField("countryCode", "Flag", 40);
              		countryCodeField.setAlign(Alignment.CENTER);
              		countryCodeField.setType(ListGridFieldType.IMAGE);
              		countryCodeField.setImageURLPrefix("flags/16/");
              		countryCodeField.setImageURLSuffix(".png");
              		countryCodeField.setCanEdit(false);
              
              		ListGridField nameField = new ListGridField("countryName", "Country");
              		ListGridField continentField = new ListGridField("continent", "Continent");
              		ListGridField memberG8Field = new ListGridField("member_g8", "Member G8");
              		ListGridField populationField = new ListGridField("population", "Population");
              		populationField.setType(ListGridFieldType.INTEGER);
              		populationField.setCellFormatter(new CellFormatter() {
              			public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
              				if (value == null)
              					return null;
              				NumberFormat nf = NumberFormat.getFormat("0,000");
              				try {
              					return nf.format(((Number) value).longValue());
              				} catch (Exception e) {
              					return value.toString();
              				}
              			}
              		});
              		ListGridField independenceField = new ListGridField("independence", "Independence");
              		countryGrid.setFields(countryCodeField, nameField, continentField, memberG8Field, populationField, independenceField);
              
              		countryGrid.setAutoFetchData(true);
              		countryGrid.setCanEdit(true);
              		countryGrid.setEditEvent(ListGridEditEvent.CLICK);
              		
              		countryGrid.addSelectionChangedHandler(new SelectionChangedHandler() {
              			
              			@Override
              			public void onSelectionChanged(SelectionEvent event) {
              				
              				// check only exit record
              				if (!event.getState()) {
              					
              					// get exit record index
              					int recordIndex = countryGrid.getRecordIndex(event.getRecord());
              					
              					Record editedRecord = countryGrid.getEditedRecord(recordIndex);
              					GWT.log("edited record " + editedRecord.getAttributeAsString("countryName"));
              					
              					Record record = countryGrid.getRecord(recordIndex);
              					
              					GWT.log("edited record 2 " + editedRecord.getAttributeAsString("countryName"));
              					
              				}
              				
              			}
              		});
              
              		countryGrid.draw();
              	}
              
              }
              and changing the datasource with transformResponse method in override, creating a ListGridRecord array as response data:

              Code:
              	@Override
              	protected void transformResponse(DSResponse response, DSRequest request, Object data) {
              		
              		Record[] responseData = response.getData();
              		ListGridRecord[] lgrData = new ListGridRecord[responseData.length];
              		for (int i = 0; i < responseData.length; i++) {
              			Record record = responseData[i];
              			lgrData[i] = new ListGridRecord();
              			for (String attribute : record.getAttributes()) {
              				lgrData[i].setAttribute(attribute, record.getAttributeAsJavaScriptObject(attribute));
              			}
              		}
              		
              		response.setData(lgrData);
              		
              	}
              Note that this is a method created to replicate the issue. In our environment we have a custom communication with the server and we process our custom response creating a ListGridRecord array to be set in DSResponse for grid's datasource.

              However i have a simple workaround: everything works fine if i clone the edited record as follow

              Code:
              	ListGridRecord editedRecord = new ListGridRecord(grid.getEditedRecord(row).getJsObj());
              	ListGridRecord oldRecord = grid.getRecord(row);
              I have post the question because I'm trying to figure out if I'm doing something wrong.
              Thanks

              Comment


                #8
                Are you able to try a current build of 4.1p? We've fixed a similar issue there.

                Comment


                  #9
                  I've tried 4.1p 30/03/2014 build but the issue is still here

                  Comment


                    #10
                    We've made a fix for this in SGWT 4.1p (it was already fixed in SGWT 5.0d). Check the next nightlies.

                    Comment


                      #11
                      The issue is resolved in nightly build 4.1p 03/04/2014.
                      Thank you.

                      Comment

                      Working...
                      X