Tuesday, April 7, 2009

Small update to GWT Exporter

I recently discovered a pretty critical bug in GWT Exporter that can cause an infinite loop doing export. This was fixed in version 2.06 which available in the trunk and maven repository.

-Ray

5 comments:

torres.sf said...

Hi Ray,

I'm trying to use gwt-export and I have a small problem, I'm not sure where I should post that is why I'm post here:
Basically, I have two exported classes the first one inherited from Label and the second should be able to receive any “Widget”, the problem is the base type of the class didn’t work. (see the code below the reproduce the problem)


@Export
public class MyWidget extends Label implements Exportable {
@Export
public void setText(String text) {
super.setText(text);
}
...

@Export
public class MyContainer implements Exportable {
// This method throw one exception
@Export
public void addWidget(Widget w) {
RootPanel.get("sd1").add(w);
}
// This method works fine
@Export
public void addMyWidget(MyWidget w) {
RootPanel.get("sd1").add(w);
}
...

JS scripts...
var label = new com.fastec.wab.MyWidget();
label.setText("Test Title");
alert(label.getText());
var container = new com.fastec.wab.MyContainer();
container.addMyWidget(label); // This work
//container.addWidget(label); // This didn't

Any idea will be great.
Regards
Torres

seb2nim said...

Hi Ray,

I'm using GWT-exporter for a while now and i want to go furter :

On one hand, GWT-Exporter allows us to export to pure-js world. On the other hand, Javascript Overlays introduced by GWT 1.5 allows us to 'wrap' pure js in Java world.

Do you have any sample implementation to bind them together ?

Just wonder if this could work :
Final goal is :
To compile a main module (Module1) which exposes objects to pure js.
To compile a second module (Module2) wich uses Javascript overlay to call main one.

I think it should be built like this : 3 modules :
"Module1-api" : Exposed objects are simple interfaces, implementation provided via defered binding is JavaScriptObject Overlay proxies.

"Module1" 'extends' (imports) "Module1-api" to redefine objects implementations as pojos + Export to js via Gwt-exporter.

"Module2" imports only "Module1-api" and uses it.

Should this work?

Any chance JsOverlay could be produced directly by generators ?

Ronen said...

Hey,

The infinite loop (stack overflow) still happens in version 2.06.

Thanks,
Ronen

Ronen said...

Hi Ray,

Not sure where to post it, but I have a problem.

I'm using an external js library that expects to receive event handlers as objects that implement all the different event callbacks.

I'm instantiating those event handler classes in GWT but when I try to pass them to the JS library, the exported methods are not part of the object.

Here is a simple code example:

@ExportPackage("exported")
public class EventHandler implements Exportable
{
static boolean exported = false;

public EventHandler()
{
registerEventHandler(this);
callEventHandler();
}

static public void export()
{
if( ! exported )
{
Exporter exporter = GWT.create(EventHandler.class);
exporter.export();
exported = true;
}
}

@Export
public void onEvent1()
{
GWT.log("onEvent1", null);
Window.alert("onEvent1");
}

public native void registerEventHandler(EventHandler handler)
/*-{
$wnd.eventHandler = handler;
}-*/;

public native void callEventHandler()
/*-{
$wnd.eventHandler.onEvent1();
}-*/;

When callEventHandler is called, I get a onEVent1 is not a member of ... error.

Thanks,
Ronen

Ronen said...

Regarding the infinite loop, it DOESN'T happen for me in 2.06.

Sorry...