Using jquery plugins with Google Web Toolkit?

3.3k views Asked by At

Is it possible to use jquery plugins within google web toolkit?

There are a lot of excellent plugins available for various UI widgets, such as date/time pickers, searchable dropdowns, etc. In many cases these plugins also come with their own css styles. I'd like to be able to use these plugins and get their values in my gwt application.

2

There are 2 answers

4
Chris Hinshaw On BEST ANSWER

From experience you have two options.

  1. You can use GwtQuery which is a gwt native version of much of jquery. For instance "$" is actually a static java class. There are also quite a few plugins and addons that have great support such as the GwtQuery-DND for drag and drop.

http://code.google.com/p/gwtquery/

http://code.google.com/p/gwtquery-plugins/

  1. The other option is to role your own for specific examples. If you have a specific jquery plugin that you want and GwtQuery is not for you. You can use gwt jsni interface which essentially allows you to call native javascript using java native interface. There are quite a few plugins that work this way such as Gflot and gcodmirror (which is a native version of the wiki editor I am using now).

JSNI Documentation
http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html

IMHO it is best to stick with GwtQuery as the jquery functions are almost verbatim usable in GwtQuery and you get the added performance boost of having the code compiled and optimized by the gwt compiler.

2
Cataclysm On

Yes .. you can use Javascript libs in GWT project. Simply import it's lib in your html file or GWT.xml. In your module.xml file as below..

<module rename-to='TestingProject'>
<inherits name='com.google.gwt.user.User'/>
<entry-point class='test.Gwt.testingSample.client.TestingProjectEntry'/>
<inherits name="com.google.gwt.user.theme.standard.Standard" />
<source path='client'/>
<source path='shared'/>
<script src="/js/jquery-1.10.min.js"></script>
</module>

And test in your HTML file..

<body>
<center>
    <div id= "start"></div>
</center>
<script type="text/javascript">
     $(document).ready(function(){
     $("div#start").html("<font color = 'green' font-weight = 'bold' size = '12'>
                          Hello World !</font>");
});
</script>
<body>

Have a useful for you... !