public native String getSomeValue() /*- {
return $wnd.someValue.
}*-/;
But be aware of "undef" !!!
should be:
public native String getSomeValue() /*- {
if($wnd.someValue){
return $wnd.someValue.
}
return null;
}*-/;
More generic:
public static native String jnsiGetString(String jsVar, String
defaultValue)/*-{
var value = eval('$wnd.'+jsVar);
if(value){
return value;
}
return defaultValue;
}-*/;
and
public String getSomeValue(){
return jnsiGetString("someValue", null);
}
HIH
On Wed, Nov 19, 2008 at 8:46 PM, Suri <[EMAIL PROTECTED]> wrote:
>
> As an update question as well,
>
> Does anyone know if this is correct syntax and if not what would be
> the correct way to go about this.
> I'm trying to copy the value of my javascript variable set in the JSP
> to the GWT client.
>
>
> -------- JSP FILE --------------
> <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 <[EMAIL PROTECTED]> 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 my JSP after 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 the JSP I have 2 options
>>
>> 1.
>> <script language=javscript>
>> var studentID = <%=request.getAttribute("studentID")%>
>> </script>
>>
>> OR
>> 2.
>> <input type="hidden" value=<%=request.getAttribute("studentID")% />
>>
>> In the case of (1) I see that we would basically HAVE to use JSNI to
>> be able to retrieve the value to GWT and then store it and use it.
>> My question is how if possible would the 2nd option implementable. Do
>> I access the DOM in some form from the GWT client code to be able to
>> access the value of the studentID (I assume before doing this I would
>> have had to have given the <input..> field an id attribute?)
>>
>> Thanks for any input
>> Suri
> >
>
--
Si l'ignorance peut servir de consolation, elle n'en est pas moins illusoire.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---