I was searching for something like this for quite some time, thanks a
million !!!

On Nov 21, 8:24 am, Suri <[EMAIL PROTECTED]> wrote:
> Aha. You're right too Olivier. Thanks for the tip. Tottally missed
> that. Appreciate it.
>
> On Nov 21, 3:55 am, "olivier nouguier" <[EMAIL PROTECTED]>
> wrote:
>
> > Hi Suri,
> >  Thanks for this tip !
> >  But IMHO in your case I think that the problem is in the hosted page:
> >  Try replacing:
> > var testVar = <%= request.getAttribute("someValue") %>
> >  by:
> > var testVar = "<%= request.getAttribute("someValue") %>"
>
> > Notice the quote !
> > Then the generate js will be:
> >   var testVar = "12345"; // a string
> > Instead of
> >  var testVar = 12345; // an int
>
> > However your solution seems pretty to me and it's better check twice
> > those JS type.
>
> > Best regards
> > Olivier.
>
> > On Thu, Nov 20, 2008 at 10:19 PM, Suri <[EMAIL PROTECTED]> wrote:
>
> > > 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
> > > On Nov 20, 11:34 am, Suri <[EMAIL PROTECTED]> wrote:
> > >> Thanks Olivier. That makes sense. I'll have to use the String and
> > >> validate it at the server side I guess.
>
> > >> Suri
>
> > >> On Nov 20, 10:08 am, "olivier nouguier" <[EMAIL PROTECTED]>
> > >> wrote:
>
> > >> > There is no long datatype in javascript !
>
> > >> >http://www.google.com/search?q=GWT+long+emulation&sourceid=navclient-...
>
> > >> > On Thu, Nov 20, 2008 at 3:31 PM, Suri <[EMAIL PROTECTED]> wrote:
>
> > >> > > Hi Olivier,
> > >> > > I actually saw your post later on another thread and used the default
> > >> > > solution. Thanks for that. Pretty neat.
> > >> > > A different question now, I observed that after obtaining the value I
> > >> > > wanted, I could not convert it to a Long type. i.e
>
> > >> > > in my client java code after retrieving the value using the native
> > >> > > method above I try something like
>
> > >> > > Long longVal = Long.parseLong("returnedValue");
>
> > >> > > And that seems to throw an error in the browser. I do remember 
> > >> > > reading
> > >> > > about some issues with Long datatype and javascript, however any
> > >> > > explanation is welcome. I'd like to understand it better.
> > >> > > Thanks
> > >> > > Suri
>
> > >> > > On Nov 20, 3:43 am, "olivier nouguier" <[EMAIL PROTECTED]>
> > >> > > wrote:
> > >> > >> 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 
> > >> > >> > theJSP
> > >> > >> > to the GWT client.
>
> > >> > >> > --------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 <[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 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
>
> > >> > >> >> 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.
>
> > >> > --
> > >> > Si l'ignorance peut servir de consolation, elle n'en est pas moins 
> > >> > illusoire.
>
> > --
> > 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 Google-Web-Toolkit@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to