Can't get a call from hand writen JavaScript to call Java-method.

Hello

From Vaadin pages / foorum and google tutorials I have understood that I should be able to call Java-function from hand writen JavaScript using this method:

http://code.google.com/intl/fi-FI/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html#calling

I have done a class as tutorial tells:

package com.example.vaadin;

public class MyUtilityClass {

public static int computeLoanInterest() {	
	return 10;
}

public static native void exportStaticMethod() /*-{
$wnd.computeLoanInterest =
	$entry(@com.example.vaadin.MyUtilityClass::computeLoanInterest());
}-*/; 

}

I call MyUtilityClass.exportStaticMethod from Vaadin applications init()-method.

When I start Vaadin application I get following error:

SEVERE: Servlet.service() for servlet Vaadin Application threw exception
java.lang.UnsatisfiedLinkError: com.example.vaadin.MyUtilityClass.exportStaticMethod()

I havent been able to find solution for my problem.

-Teemu

You can only call Java methods that are compiled to the client side part of the application (GWT widgetset). And GWT expects all client side classes to be found under package named *.client, with the widgetset XML file residing before in the hierarchy:


com
  example
    vaadin
      MyWidgetSet.gwt.xml
      client
        MyUtilityClass.java

Thanks for the reply and pointing me to right direction.
Now Im able to get my classes compiled atleast. But Im still having problem. I cant get call to my Client side Java method to work from hand writen JavaScript.

I used Vaadin Eclipse plugins “Create Widget” functionality. And named my widget to MyComponent.

Now I have client side class VMyComponent.java and server side class MyComponenet.java.
I added previously mentioned exportStaticMethod()- and computeLoanInterest()- methods to VMyComponenet class and call exportStaticMethod()-method from VMyComponet classes onLoad()-method.

Widget works and it counts my clicks and shos the count at client side.

From hand writen JavaScript Im trying to call computeLoanInterest() just by running alert(‘Works:’+computeLoanInterest() )

Im doing something wrong but dont know what. Im totally newbie when it comes to Vaadin. Any fast ideas what Im doing wrong?

I tried with this approach, didnt get it to work either:

[url=http://vaadin.com/forum/-/message_boards/message/212618?_19_redirect=%2Fforum%2F-%2Fmessage_boards%2Fsearch%3F_19_redirect%3D%252Fforum%252F-%252Fmessage_boards%252Fcategory%252F11566%26_19_breadcrumbsCategoryId%3D11566%26_19_searchCategoryId%3D11566%26_19_tabs1TabsScroll%3D%26_19_keywords%3Djavascript]
Vaadin foorum: custom component with publishing API to invoke from javascript

[/url]

Now it works. My problem was that I had added my Widget to TabSheets second tab. And When Vaadin application was loaded I tried to call My Widgets method from JavaScript at applications init metod.

Because widget was at second tab it was never loaded during application init, thus method was never registered. I moved widget to first page of my application and now it got loaded before I called its function from JavaScript.

Thanks again for pointing me to right direction.