You've got to expose DB_DATA to Java for this to work.
Maybe use Javascript overlays
(http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsOverlay.html),
and call out to Java from JSNI instead of referencing DB_DATA
"directly". I write "directly" since there's more hand-written code
involved than what actually executes.

On 07/19/2011 11:45 PM, "Ionuț G. Stan" wrote:
> Hi,
> 
> Whenever I'm working in JS, I find myself times and times again using a
> certain pattern in order to avoid an extra call to the server. I dump
> into the web page a JSON object (serialized by the server) inside a
> SCRIPT tag that is then interpreted by the browser as part of the normal
> flow. The alternative would be to make an additional Ajax request, which
> is unnecessary form my point of view.
> 
> For example:
> 
> <script>
> var DB_DATA = {
>    users: <?php echo json_encode(fetch_users_from_db()); ?>
> };
> 
> window.onload = function () {
>    // disp
>    display_users(DB_DATA.users);
> 
>    refreshButton.onclick = function () {
>      fetch_users_from_server(function (users) {
>        display_users(users);
>      });
>    };
> };
> </script>
> 
> 
> As far as my GWT knowledge goes, I can do the same thing in GWT using
> JSNI, with something like this:
> 
> public native void displayUsers()/* {
>   display_users(DB_DATA.users);
> } */;
> 
> However, I was wondering if there's some GWT specific pattern, that
> would also allow some compile time checks for the presence of the
> generated JS variable (similar to how CSS files are checked to see if
> all the required CSS classes are declared).
> 
> Thanks!

-- 
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 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to