Re: GWT native to long conversion

2015-08-02 Thread Nikolay Prokofiev
Thanks!

суббота, 1 августа 2015 г., 18:07:56 UTC-4 пользователь Alberto Mancini 
написал:
>
> Hello,
> in your example you are returning  id (a numeric value) as a string ant 
> this is the origin of the unexpected behavior.
> Indeed this works
>
> public final native String  _getIdString()/*-{ return ''+this.id; }-*/;
>
> as well as returning a java numeric value:
>
> public final native int  _getIdInt()/*-{ return this.id; }-*/;
> (see 
> http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html#passing-javascript
>  
> for details)
>
> Anyway, in general, is probably not a good idea to use Long for a numeric 
> 'native'  value  
> because in js you cannot represent a long number (see f.e. 
> http://stackoverflow.com/questions/17320706/javascript-long-integer).
>
> Hope it helps.
> 
>   Alberto. 
>
>
>
> On Sat, Aug 1, 2015 at 3:38 PM Nikolay Prokofiev  > wrote:
>
>> Hi.
>>
>> I'm trying to convert js native number to GWT Long and send it over 
>> gwt-rpc. But I got very weird results..
>>
>> public class gwtbugEntryPoint implements EntryPoint {
>>   @Override
>>   public void onModuleLoad() {
>> String data = "{\"type\":\"upd\", \"id\":123}";
>> ServerEvent serverEvent = JsonUtils.safeEval(data);
>> RootPanel.get().add(new HTML("GWT id="+serverEvent.getId()));
>>   }
>> }class ServerEvent extends JavaScriptObject {
>> protected ServerEvent() {
>> }
>> public final native String getType()/*-{ return this.type; }-*/;
>> public final Long getId(){
>> String idStr = _getId();
>> GWT.log("idSTr:" + idStr);
>> Long id = new Long(idStr);
>> GWT.log("id:"+id);
>> return id;}
>> public final native String  _getId()/*-{ return this.id; }-*/;}
>>
>> console output:
>>
>> idSTr:123
>>
>> id:0
>>
>> Can anyone explain me, how that could happen?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Google Web Toolkit" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to google-web-toolkit+unsubscr...@googlegroups.com .
>> To post to this group, send email to google-we...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/google-web-toolkit.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.


Re: GWT native to long conversion

2015-08-01 Thread Nagin Kothari
instead of

Long id = new Long(idStr);

try

Long id = Long.parseLong(idStr);



On Sun, Aug 2, 2015 at 3:37 AM, Alberto Mancini 
wrote:

> Hello,
> in your example you are returning  id (a numeric value) as a string ant
> this is the origin of the unexpected behavior.
> Indeed this works
>
> public final native String  _getIdString()/*-{ return ''+this.id; }-*/;
>
> as well as returning a java numeric value:
>
> public final native int  _getIdInt()/*-{ return this.id; }-*/;
> (see
> http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html#passing-javascript
> for details)
>
> Anyway, in general, is probably not a good idea to use Long for a numeric
> 'native'  value
> because in js you cannot represent a long number (see f.e.
> http://stackoverflow.com/questions/17320706/javascript-long-integer).
>
> Hope it helps.
>
>   Alberto.
>
>
>
> On Sat, Aug 1, 2015 at 3:38 PM Nikolay Prokofiev 
> wrote:
>
>> Hi.
>>
>> I'm trying to convert js native number to GWT Long and send it over
>> gwt-rpc. But I got very weird results..
>>
>> public class gwtbugEntryPoint implements EntryPoint {
>>   @Override
>>   public void onModuleLoad() {
>> String data = "{\"type\":\"upd\", \"id\":123}";
>> ServerEvent serverEvent = JsonUtils.safeEval(data);
>> RootPanel.get().add(new HTML("GWT id="+serverEvent.getId()));
>>   }
>> }class ServerEvent extends JavaScriptObject {
>> protected ServerEvent() {
>> }
>> public final native String getType()/*-{ return this.type; }-*/;
>> public final Long getId(){
>> String idStr = _getId();
>> GWT.log("idSTr:" + idStr);
>> Long id = new Long(idStr);
>> GWT.log("id:"+id);
>> return id;}
>> public final native String  _getId()/*-{ return this.id; }-*/;}
>>
>> console output:
>>
>> idSTr:123
>>
>> id:0
>>
>> Can anyone explain me, how that could happen?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google Web Toolkit" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to google-web-toolkit+unsubscr...@googlegroups.com.
>> To post to this group, send email to google-web-toolkit@googlegroups.com.
>> Visit this group at http://groups.google.com/group/google-web-toolkit.
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-web-toolkit+unsubscr...@googlegroups.com.
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> Visit this group at http://groups.google.com/group/google-web-toolkit.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Nagin Kothari
Co-founder,
Zilicus Solutions
www.zilicus.com

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.


Re: GWT native to long conversion

2015-08-01 Thread Alberto Mancini
Hello,
in your example you are returning  id (a numeric value) as a string ant
this is the origin of the unexpected behavior.
Indeed this works

public final native String  _getIdString()/*-{ return ''+this.id; }-*/;

as well as returning a java numeric value:

public final native int  _getIdInt()/*-{ return this.id; }-*/;
(see
http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html#passing-javascript
for details)

Anyway, in general, is probably not a good idea to use Long for a numeric
'native'  value
because in js you cannot represent a long number (see f.e.
http://stackoverflow.com/questions/17320706/javascript-long-integer).

Hope it helps.

  Alberto.



On Sat, Aug 1, 2015 at 3:38 PM Nikolay Prokofiev 
wrote:

> Hi.
>
> I'm trying to convert js native number to GWT Long and send it over
> gwt-rpc. But I got very weird results..
>
> public class gwtbugEntryPoint implements EntryPoint {
>   @Override
>   public void onModuleLoad() {
> String data = "{\"type\":\"upd\", \"id\":123}";
> ServerEvent serverEvent = JsonUtils.safeEval(data);
> RootPanel.get().add(new HTML("GWT id="+serverEvent.getId()));
>   }
> }class ServerEvent extends JavaScriptObject {
> protected ServerEvent() {
> }
> public final native String getType()/*-{ return this.type; }-*/;
> public final Long getId(){
> String idStr = _getId();
> GWT.log("idSTr:" + idStr);
> Long id = new Long(idStr);
> GWT.log("id:"+id);
> return id;}
> public final native String  _getId()/*-{ return this.id; }-*/;}
>
> console output:
>
> idSTr:123
>
> id:0
>
> Can anyone explain me, how that could happen?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-web-toolkit+unsubscr...@googlegroups.com.
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> Visit this group at http://groups.google.com/group/google-web-toolkit.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.


GWT native to long conversion

2015-08-01 Thread Nikolay Prokofiev


Hi.

I'm trying to convert js native number to GWT Long and send it over 
gwt-rpc. But I got very weird results..

public class gwtbugEntryPoint implements EntryPoint {
  @Override
  public void onModuleLoad() {
String data = "{\"type\":\"upd\", \"id\":123}";
ServerEvent serverEvent = JsonUtils.safeEval(data);
RootPanel.get().add(new HTML("GWT id="+serverEvent.getId()));
  }
}class ServerEvent extends JavaScriptObject {
protected ServerEvent() {
}
public final native String getType()/*-{ return this.type; }-*/;
public final Long getId(){
String idStr = _getId();
GWT.log("idSTr:" + idStr);
Long id = new Long(idStr);
GWT.log("id:"+id);
return id;}
public final native String  _getId()/*-{ return this.id; }-*/;}

console output:

idSTr:123

id:0

Can anyone explain me, how that could happen?

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.