How to use GWTChosen in a GWT application

To follow up on our blog post about the release of GWTChosen 3.0 last week, we wanted to offer a little tutorial on how to use GWTChosen in a GWT or GWTP application.


Suppose you are using Maven on a regular GWT application (if you are not using Maven, you’ll need to have the JARs of these dependencies installed in your PATH).

There are 3 dependencies that you need. First, GWTChosen depends on GQuery, so you’ll need to have GQuery among them. You’ll also need Guava-GWT (for the Collect GWT Module) and the GWTChosen dependency itself.

It should look like this (in your pom.xml) :

Install the GWT Modules

You’ll also have to install the GWT Module corresponding to the GWTChosen dependency :

<inherits name="com.arcbees.chosen.Chosen"/>

Load GWTChosen

Once these steps are complete, you’re ready to use GWTChosen.

If you are using the widget in UiBinder, you’ll need to add this line in the opening XML UiBinder tag :


In UiBinder, when you want to declare it, you are then able to write something like this :

The Simple Chosen widget is now on your page.

If we want to use the Multiple Values Chosen instead, it will take a bit more work. We have to declare it dynamically (which is also possible with the Simple Value option). We only declare the object in the UiBinder, but not the values and the parameters :

Here’s an example of what we can do in our Java class as a result (this example is with GWTP, but it would be exactly the same idea with pure GWT) :

Now you have a Chosen Widget where you’ll be able to select multiple elements, and dynamically add or remove elements, if you want.

I hope this helped clarify how GWTChosen works, and how to set it up. If you want the detailed code for this example, you can find it here on GitHub. For more details and additional features, explore our documentation.

If you have any other questions about GWTChosen, there will be a Q&A with Maxime and I next week. We look forward to meeting you online and answering any questions you may have.

Also, don’t forget to subscribe to our newsletter to be informed when there is new content on our blog!