The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

LeLLuMe (1) [Avatar] Offline
#1
Hi,
i'm trying to write a wrapper fot the JavaScript library Flotr (http://solutoire.com/flotr/).

This is the code:

Definition of the GWT Implementation Class

public class ClassFlotrImpl {

public native ClassFlotr disegna(Element elemento)
/*-{
var d1 = [[4, 6], [3, 9], [12, 5], [5, 34]];
var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]];
var f = $wnd.Flotr.draw(elemento, [ d1, d2 ]);

return f
{-*/;
}


Definition of the GWT JavaScriptObjectClass

public class ClassFlotr extends JavaScriptObject {
private static ClassFlotrImpl grafico = new ClassFlotrImpl();

public static ClassFlotr disegna(Element elemento){
return(grafico.disegna(elemento));
}

}


Definition of the GWT Widget Class

public class ClassFlotrWidget extends Composite {
VerticalPanel area = new VerticalPanel();
VerticalPanel areaGrafico = new VerticalPanel();
static ClassFlotr grafico = null;

public ClassFlotrWidget (){
areaGrafico.setHeight("600px");
areaGrafico.setWidth("300px");
area.add(areaGrafico);
initWidget(area);
disegna(areaGrafico.getElement());
}

public ClassFlotr disegna(Element elemento){
if (grafico == null){
grafico = grafico.disegna(elemento);
}
return grafico;
}

}


The calling code

...
ClassFlotrWidget flotrw = new ClassFlotrWidget();
RootPanel.get("plotsContainer").add(flotrw);


The code seems to be right, but despite that, at runtime the follow error message appears:
[ERROR] No JavaScript body found for native method 'public native it.uniba.di.client.ClassFlotr disegna(com.google.gwt.user.client.Element elemento)' in type 'class it.uniba.di.client.ClassFlotrImpl'

Why? Can you help me?

Best regards.

Lello
adam.tacy (269) [Avatar] Offline
#2
Re: No JavaScript body found for native method...
HI,

I'm taking a bit of a stab in the dark here, but I think there are two things wrong with your JSNI description in ClassFlotrImpl

1) You have /*-{ on a separate line from the method declaration - though shouldn't really be a problem
2) You have {-*/ at the end of your body as opposed to }-*/ - this is probably the issue, unless you've just made a type in the post and in the code it is correct.....

I would tweak both of those and see what it gets you.

Regards,

Adam
Maerch (1) [Avatar] Offline
#3
Re: No JavaScript body found for native method...
Hello,

i tried the code with the two suggestions from adam.tracy. Now there is no failure instead of this it draws simply nothing with

"RootPanel.get().add(flotrw);"

Has the author of this thread solved the problem and if yes than how?

Or can anybody else explain me what the reason is?
The Flotr *.js files are included to GWT successfully and this library draws a chart with JS in a HTML site (see code-snippet). How can i wrap this in GWT?

I would be very thankful for every hint or suggestion or even a link to a site which could help me.

Regards Maerch

/**
* Fill series d1 and d2.
*/
var d1 = [];
for(var i = 0; i < 14; i += 0.5)
d1.push([i, Math.sin(i)]);

var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]];

/**
* Draw the graph.
*/
Flotr.draw($('container'), [ d1, d2 ]);