What is the process of generating a fresh JavaScript object using GWT JSNI?

Is there a way to create a new JavaScript object from GWT using JSNI? I can't seem to find any information in the documentation. I did manage to make it work by moving all the JS code to .html files, but that caused another unrelated problem.

Here is the Java code snippet:

private static native void createPicker() /*-{
    var picker = new $wnd.google.picker.PickerBuilder()
        .enableFeature(google.picker.Feature.NAV_HIDDEN)
        ....

However, I encountered the following error:

com.google.gwt.event.shared.UmbrellaException: Exception caught: (ReferenceError) @com.onix.sdm.client.SDM_Mailer::createPicker()([]): google is not defined

Upon checking the browser console, I found that the 'google' object is indeed defined:

> google
  >Object {picker: Object}

For more information, you can refer to this link.

Below is the relevant HTML code:

<script type="text/javascript">
    function loadPicker() {
      gapi.load('picker');
    }
</script>
<script type="text/javascript" src="https://apis.google.com/js/api.js?onload=loadPicker"></script>

Answer №1

There was a multitude of variables that needed to be prefixed with a package name. It wasn't just the new object that required a prefix, but every variable as well, for example:

var view = new $wnd.google.picker.DocsView($wnd.google.picker.ViewId.FOLDERS);

.enableFeature($wnd.google.picker.Feature.NAV_HIDDEN)

It was quite cumbersome, no line numbers provided, but that's what they compensate me for.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

html line breaks $.parseJSON

Within my website, I am currently utilizing a TinyMCE window. The method involves PHP fetching an entry from the database, decoding it as JSON, and then having in-page JavaScript parse it. However, issues arise when there are elements like style='colo ...

What is the best way to retain previous values without using an object array to store values in a React state?

My approach involves storing the previous values in an array of objects, where each object represents a key-value pair. For example: [{ActFollow: 'BlN'},{ActSendGift: 'BlY'},{ActSubscribe: 'BlY'}]. However, I aim to transform ...

Xap or js Silverlight media player

Currently developing a Silverlight video player, I stumbled upon the JW Player for inspiration. I know that Silverlight apps are typically contained within .xap files, but JW Player utilizes JavaScript scripts to implement Silverlight logic. Can you plea ...

Adjust the height of images to be consistent

I'm currently working on creating a grid layout with 4 images in a row using DaisyUI card component. However, I've run into an issue where there is white space at the bottom of some images due to varying image heights. Is there a solution that wo ...

Remove user from firebase with Admin SDK

I need help understanding how to remove a user from my admin panel using the Firebase Admin SDK. When attempting to delete a user, I encountered this error: Uncaught (in promise) ReferenceError: uid is not defined at eval (ManageCustomer. ...

Implementing a file download feature in Python when clicking on a hyperlink

I'm attempting to click on the href link below. href="javascript:;" <div class="xlsdownload"> <a id="downloadOCTable" download="data-download.csv" href="javascript:;" onclick=&q ...

Remove the "x" character from the phone field if an extension is not provided in the Jquery masked input plugin

Currently utilizing the jquery Masked input plugin. The mask I have applied to a field is as follows: "?999-999-9999 x9999" Why is there a ? at the beginning? This was implemented to prevent the field from clearing out when an incomplete number is ente ...

Flask-SocketIO: Transmitting data between nodes using Redis adapter

When integrating SocketIO into an application running behind a node-balancer, the documentation recommends using SocketIO-Redis to facilitate event passing between nodes: const io = require('socket.io')(3000); const redis = require('socket.i ...

Developing and integrating views within a node-webkit desktop application

For my file copier desktop application built with node webkit, I aim to create a seamless flow where the initial check for existing profile data determines the first page displayed. The header with static links/buttons to various views remains consistent ...

Python: Mimicking Splinter/Selenium Functionality to Test a JavaScript-Driven Website

My automated bot interacts with a dynamic website using Splinter and Selenium. Despite its effectiveness most of the time, it occasionally encounters exceptions due to random events. Debugging these occurrences is quite challenging, especially since the we ...

Exploring the relationship between waits and notify in Java concurrency and how they can lead to dead

I am currently learning about basic concurrency in Java and have come across an interesting exercise in my Java book. The exercise involves implementing a reader-writer-problem with 3 readers and 3 writers. The main class, writer class, and reader class we ...

What is the best way to reset an angularJS form after it has been submitted

I am trying to figure out a way to clear form fields on a modal window after the user executes the save method. I have attempted using $setPristine in AngularJS, but it's not working as expected. Any suggestions on how to achieve this task? Here is t ...

Obtaining Google AAID Using a Mobile Browser (JavaScript)

I've been looking for information online without much success regarding this topic. I am interested in retrieving a user's Google Advertising ID (AAID) through my website when they visit using a mobile browser. I assume it could be done with som ...

Unable to update a single object within an array using the spread operator

I am currently working on updating an object within an array and have encountered some issues. In my initial code, I successfully updated a specific property of the object inside the array like this: var equipment = this.equipments.find((e) => e.id === ...

The scrolling feature induces a contraction to the left side

Recently, I implemented the code below to fix my menu when scrolling the page: var num = 5; $(window).bind('scroll', function () { if ($(window).scrollTop() > num) { $('.scroll').css({'position':'fixed&apo ...

Issue with Zebra_Calendar and JSON compatibility in Internet Explorer 7

I have integrated the Zebra_Calendar jQuery plugin on my website, but encountered an issue when including a JSON implementation. Specifically, I am facing an "Object Doesn't Support This Property or Method" error related to string.split during initial ...

What exactly is the functionality of the `require('atom')` method?

Atom provides various global APIs that can be easily accessed through require('atom') How does this mechanism function? Despite not being a declared dependency, Atom packages are able to utilize these global APIs. Additionally, is it possible to ...

Select2 eliminates every tag except the first one

I am currently utilizing Select2 in Django for handling many-to-many relationships. The best approach I have found to handle all validation constraints is to create related objects through an AJAX request as soon as they are entered into the Select2 tag fi ...

Tips for utilizing json put to append data:

My task involves extracting specific fields from a database related to stores in the same locality. The desired output format is JSON. Below is the code snippet I am currently using: JSONObject result = null; String sqlQuery = "SELECT STORE, LOCA ...

Preventing click event from bubbling up the DOM: Using Vue's @click

How can I access the child elements within a parent component? <div v-on:click.stop.prevent="onClickTemplateHandler"> <div> <h3 style="">Title</h3> <p>{{ lorem }}</p> </div> ...