Dynamic JSNI assignments within GWT

62 views
Skip to first unread message

AcidCow

unread,
May 7, 2007, 9:25:59 AM5/7/07
to Google Web Toolkit
In order to make life simple for those around me that are not yet up
to speed with GWT and the idea of asynchronous calls... I would like
to write a generic JSNI datasource type component that does an asynch
call (get/post) to a specified server, and then once the responseText
is received I'd like to shove it into whatever variable is
specified...

I have got it working with a specified JSNI path as a return
parameter. ie: "x...@com.google.gwt.secure.whocares::splurb =
responseString;"
where "x...@com.google.gwt.secure.whocares::splurb" is specified as a
parameter.

however, due to said others not knowing what this all means and how it
all fits together... I would like to simplify things a bit further...
is it possible to retrieve said return path etc from a variable that
is passed?
ie: is there a function I can call on the parameter to get such a
string or any javascript etc that might allow me to simply return the
string to one of the variables passed in the parameters?
at first I thought merely setting one of the parameters might work
since javascript is reference based, but was very quickly proven
dismally wrong.

:)

Ian Petersen

unread,
May 7, 2007, 10:46:04 AM5/7/07
to Google-We...@googlegroups.com
I'm not 100% sure about this, but I doubt you'll be able to store a
string like "x...@com.google.gwt.secure.whocares::splurb" in a parameter,
and then evaluate it at runtime. The syntax GWT uses for accessing
Java methods and fields from JSNI is not valid Javascript so the
compiler must be turning it in to something else before it generates
its output. This is a long-winded way of saying I think that strings
like "x...@com.google.gwt.secure.whocares::splurb" have to be literals.

Ian

--
Tired of pop-ups, security holes, and spyware?
Try Firefox: http://www.getfirefox.com

Reinier Zwitserloot

unread,
May 8, 2007, 11:22:50 AM5/8/07
to Google Web Toolkit
Indeed; what Ian said.

You'll need to use pointers. With generics you can make some very
nifty hacks, but lacking those, I suggest an array of size 1, which is
effectively a pointer as well. You pass the array reference to your
method, JSNI or not, and on return you stuff the result in
arrayReference[0].

I sort of fail to see the use of this though. Knowing when the info is
actually filled (e.g. a callback) sounds useful to me.

AcidCow

unread,
May 10, 2007, 6:18:39 AM5/10/07
to Google Web Toolkit
My bad, I found out shortly after posting that query that I had infact
left the string in the JSNI after creating said parameter to pass the
string through - and was thus not using it as a parameter at all.
...and no - it doesn't work as a parameter (as I did find out). :D
array idea - will have a look at that... might be the solution I need.
however, had just got fed up with the idea and people will simply have
to create a responseTextHandler for and AsyncGet(..) and can get the
resultant value from a BlockingGet() : string. I j ust hope that they
don't only use the blocking get since it does exactly that - it blocks
the thread till the result is captured.
next stop would be to create a non-blocking inline get (using a
delayed timer etc). yay... and here I thought this might be a
thrilling project... yay.


On May 8, 5:22 pm, Reinier Zwitserloot <reini...@gmail.com> wrote:
> Indeed; what Ian said.
>
> You'll need to use pointers. With generics you can make some very
> nifty hacks, but lacking those, I suggest an array of size 1, which is
> effectively a pointer as well. You pass the array reference to your

> method,JSNIor not, and on return you stuff the result in


> arrayReference[0].
>
> I sort of fail to see the use of this though. Knowing when the info is
> actually filled (e.g. a callback) sounds useful to me.
>
> On May 7, 4:46 pm, "Ian Petersen" <ispet...@gmail.com> wrote:
>
> > I'm not 100% sure about this, but I doubt you'll be able to store a
> > string like "x...@com.google.gwt.secure.whocares::splurb" in a parameter,
> > and then evaluate it at runtime. The syntax GWT uses for accessing

> > Java methods and fields fromJSNIis not valid Javascript so the

Reinier Zwitserloot

unread,
May 10, 2007, 1:46:36 PM5/10/07
to Google Web Toolkit
blocking get?

You do realize your website's users will curse your name and dance on
your grave? blocking in javascript means the whole browser is down
until the blocking is over. If you're very lucky, the browser will
call you on your silly blocking scheme and offer the user the option
to shut you down, at which point your app stops working.

Bad, bad, baaahaaaad idea.

Learn to write anonymous inner classes.

Reply all
Reply to author
Forward
0 new messages