google-code-export / smartgwt

Automatically exported from code.google.com/p/smartgwt
1 stars 3 forks source link

ListGridRecord not returning original value #704

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Here is my standalone EntryPoint that shows the bug.
What I get on the screen is this.
Value=413473029467467000
Value2=413473029467467008
That should prove that SmartGWT did not return the long value that you actually 
passed into the Record.

Code starts here:

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.VLayout;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Smartgwt_test implements EntryPoint {

  /**
   * {@inheritDoc}
   */
  @Override
  public void onModuleLoad() {

    ListGridRecord record = new ListGridRecord();
    Long value = Long.valueOf(413473029467467000L);
    String property = "long";
    record.setAttribute(property, value);
    Long value2 = record.getAttributeAsLong(property);
    VLayout layout = new VLayout();
    layout.addMember(new Label("Value=" + value.toString()));
    layout.addMember(new Label("Value2=" + value2.toString()));
    layout.show();
    // assert (value.equals(value2));
  }
}

Original issue reported on code.google.com by joerg.ho...@googlemail.com on 6 Feb 2013 at 2:21

GoogleCodeExporter commented 9 years ago
Tested with SmartGWT 3.1 (v8.3p_2012-11-23) as well as some older nightly build 
(v8.3p_2012-11-30).

Original comment by joerg.ho...@googlemail.com on 6 Feb 2013 at 2:36

GoogleCodeExporter commented 9 years ago
By default, this value is internally stored as a JavaScript Number, and 
JavaScript lacks the range to store integral values this large.

We recommend using a String instead to represent a value like this, which we 
assume is really a unique ID rather than a numeric value you plan to do math 
with.

It's also possible to use SimpleType with a ValueExtractor/ValueUpdater to have 
a Record store a value that is internally represented as a Java Long.  But 
there is little point in doing this if the value is just an ID - String works 
better for that.

We may eventually add a SimpleType as described above as a framework feature, 
but we don't plan to have the framework switch over to this strategy by default 
as it is much slower.  This means that the code above will still be expected to 
round off Long values, and you would you would have to declare a 
DataSourceField with a special type in order to switch over to the slower 
storage strategy that allows the full range of Java Long.

Original comment by smartgwt...@gmail.com on 6 Feb 2013 at 3:56

GoogleCodeExporter commented 9 years ago
Thanks for clarification.

> We may eventually add a SimpleType as described above as a framework feature, 
> but we don't plan to have the framework switch over to this strategy by 
> default as it is much slower.

I do understand this, but it should be documented explicitly. Maybe even an 
assert should be considered to warn developers if they are (mis)using record 
fields for to large values.

As a "regular" GWT developer you do not expect this as GWT supports this and 
documents it:
https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsCompati
bility

Original comment by joerg.ho...@googlemail.com on 18 Feb 2013 at 9:23