gwtgxt

How to call a GWT method from javascript code


I am using following block of code in ListView of Gxt component, and onRender the following template will be set to the default. I could able to render the component with image + model value. I want to write onClick event for rendered image.

Here the place i am setting template to ListView.

 rightListView.setTemplate(getTemplate(moduleBaseURL));

template setting :

private native String getTemplate(String base) /*-{  
return ['<tpl for=".">',  
'<div class="thumb"><img src="'+base+'images/default/tabs/tab-close.gif" width="15" height="15" style="CURSOR:pointer"/>{bookCode}</div>',  
'</div>',  
'</tpl>',  
''].join("");  

}-*/;

Screen Shot:

enter image description here

On click of close image, i have some gwt code to be executed, is there any way to do this.


Solution

  • Yes.. you can write native javascript inside your gwt code.

        public static native void exportMyFunction() /*-{
           $wnd.myFunction =
              $entry(@com.myCompany.myProject.client.myClass::onCloseGwtFunction()());
        }-*/;
        public static void onCloseGwtFunction()
        {
           // your gwt code to be executed 
        }
    

    When your app is initializing you must call exportMyFunction() from gwt class. and you can give

    <img onClick='window.myFunction()' src="'+base+'images/default/tabs/tab-close.gif" width="15" height="15" style="CURSOR:pointer" /> 
    

    in your onclick from your close image