Hi Olivier,
I just thought I'd let you know. The script you have works great
however needs one additional modification.
public static native String jnsiGetString(String jsVar, String
defaultValue)/*-{
var value = eval('$wnd.'+jsVar);
if(value){
return value.toString();
}
return defaultValue;
}-*/;
and
public String getSomeValue(){
return jnsiGetString("someValue", null);
}
Notice the .toString(). This is so that the value being returned is
truly converted to a String datatype. As part of doing some work I had
used the script but the variable that was being referenced, happened
to have a numeric value. Thus, when trying to do an RPC, the system
kept giving me a ClassCastException although I was sure I was passing
a String (it also passed the instanceof test) but once I put
the .toString() it worked correctly. I guess something funky happens
there no idea what. e.g
--- JSP-----------------
<script language="javascript" type="text/javascript">
// someValue happens to be an integer although its sent as a String
in Java e.g "123456"
var testVar = <%= request.getAttribute("someValue") %>
</script>
---------------------------
----- Client Code ------------
.......
String testValue = getString("testVar", "0");
// Although this executes correctly and works fine, it acts up later
in the code unless the .toString() method is called in the javascript
as shown before.
------------------------------------
Thanks
Suri
> > >> > --------JSPFILE --------------
> > >> > <script language="javascript" type="text/javascript">
>
> > >> > var someValue = <%= (String) request.getAttribute("someValue")
> > >> > %>
>
> > >> > </script>
> > >> > ------------------------------------ GWT ENTRY POINT CLIENT CLASS
> > >> > ---------------------
>
> > >> > public class SomeClass
> > >> > {
> > >> > private String someValue;
>
> > >> > public onModuleLoad()
> > >> > {
> > >> > this.someValue = getSomeValue;
> > >> > }
>
> > >> > public native String getSomeValue() /*- {
> > >> > return someValue;
> > >> > } -*/
>
> > >> > }
> > >> > ----------------------------------------------------------------------------------------------------------------
>
> > >> > Thanks.
>
> > >> > On Nov 19, 11:40 am, Suri <
sviswanad...@gmail.com> wrote:
> > >> >> Hi,
> > >> >> This must've been asked a million times and I tried looking but the
> > >> >> only answer I got was JSNI in most cases. I just want to be sure its
> > >> >> the only way. Assuming I was passing data to myJSPafter my action
> > >> >> has completed. Lets say a value for a studentID.
> > >> >> Now in my GWT module I'll need this studentID so that I can then load
> > >> >> up information about that student using GWT code.
> > >> >> In theJSPI have 2 options