Skip to main content

SuggestBox in GWT UiBuinder

I am currently working also on a project hosted on Google App Engine (http://appspot.com) and I want to share some tips about some of the frameworks offered by the GAE environment.
Today I want to talk about a problem we had using the GWT SuggestBox component while making UiBinder layouts. The class com.google.gwt.user.client.ui.SuggestBox is a text box or text area which displays a pre-configured set of selections that match the user's input. Each SuggestBox is associated with a single com.google.gwt.user.client.ui.SuggestOracle. The SuggestOracle is used to provide a set of selections given a specific query string. Our application provides a method to retrieve suggestions from the backend while a user writes into the SuggestBox. This worked fine with a GWT Java layout, but moving to UiBinder layout we faced the following problem. We added a SuggestBox to a view through the GWT designer. The code generated was the following:

View.ui.xml:
<g:SuggestBox ui:field="fromSuggestBox"/>
View.java:

@UiField
SuggestBox fromSuggestBox;
Then we added to the View class the method to populate the MultiWordSuggestOracle to be passed to the SuggestBox:
private MultiWordSuggestOracle createOracle() {
        MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
        ...
        // Code to retrieve values
        ...
        return oracle;
}
So we set the attribute provided to true for the @UiField annotation
@UiField(provided = true)
SuggestBox fromSuggestBox;
and tried to manually create the SuggestBox instance into the constructor of the View class before invoking 
the initWidget method
public Tracking(String firstName) {
        SuggestBox fromSuggestBox = new SuggestBox(createOracle());
        initWidget(uiBinder.createAndBindUi(this));
}
But the application throwed an exception at runtime while rendering the view. This doesn't work. The only way to populate a SuggestBox in a UiBinder view is to create the Suggest Box instance while declaring it

@UiField(provided = true)
SuggestBox fromSuggestBox = new SuggestBox(createOracle());
and not inside the View class constructor.


Comments

  1. Thanks a lot.. spend a lot of time in rectifying the error...
    It will work only when we declare like -
    @UiField(provided = true)
    SuggestBox box = new SuggestBox(createOracle());

    ReplyDelete

Post a Comment

Popular posts from this blog

Turning Python Scripts into Working Web Apps Quickly with Streamlit

 I just realized that I am using Streamlit since almost one year now, posted about in Twitter or LinkedIn several times, but never wrote a blog post about it before. Communication in Data Science and Machine Learning is the key. Being able to showcase work in progress and share results with the business makes the difference. Verbal and non-verbal communication skills are important. Having some tool that could support you in this kind of conversation with a mixed audience that couldn't have a technical background or would like to hear in terms of results and business value would be of great help. I found that Streamlit fits well this scenario. Streamlit is an Open Source (Apache License 2.0) Python framework that turns data or ML scripts into shareable web apps in minutes (no kidding). Python only: no front‑end experience required. To start with Streamlit, just install it through pip (it is available in Anaconda too): pip install streamlit and you are ready to execute the working de...

Load testing MongoDB using JMeter

Apache JMeter ( http://jmeter.apache.org/ ) added support for MongoDB since its 2.10 release. In this post I am referring to the latest JMeter release (2.13). A preliminary JMeter setup is needed before starting your first test plan for MongoDB. It uses Groovy as scripting reference language, so Groovy needs to be set up for our favorite load testing tool. Follow these steps to complete the set up: Download Groovy from the official website ( http://www.groovy-lang.org/download.html ). In this post I am referring to the Groovy release 2.4.4, but using later versions is fine. Copy the groovy-all-2.4.4.jar to the $JMETER_HOME/lib folder. Restart JMeter if it was running while adding the Groovy JAR file. Now you can start creating a test plan for MongoDB load testing. From the UI select the MongoDB template ( File -> Templates... ). The new test plan has a MongoDB Source Config element. Here you have to setup the connection details for the database to be tested: The Threa...

Evaluating Pinpoint APM (Part 1)

I started a journey evaluating Open Source alternatives to commercial New Relic and AppDynamics tools to check if some is really ready to be used in a production environment. One cross-platform Application Performance Management (APM) tool that particularly caught my attention is Pinpoint . The current release supports mostly Java applications and JEE application servers and provides support also for the most popular OS and commercial relational databases. APIs are available to implement new plugins to support specific systems. Pinpoint has been modeled after Google Dapper and promises to install agents without changing a single line of code and mininal impact (about 3% increase in resource usage) on applications performance. Pinpoint is licensed under the Apache License, Version 2.0 . Architecture Pinpoint has three main components:  - The collector: it receives monitoring data from the profiled applications. It stores those information in HBase .  - The web UI: the f...