Pregunta

we're using SmartGWT LGPL 4.0 and now we're messing around with file upload with callback using a hidden iFrame (deffined in the same canvas as the DynamicForm). In the response from server after uploading the file, we're sending back some javascript test code like alerts that are being executed. The problem comes when trying to access a JSNI method defined in the same DynamicForm file as public static. In the javascript code sended back as response we're calling the method via "window.parent.document.callbackMethod()" but we're getting an error saying the function is not defined. Seems that "window.parent.document" is not the proper way to access the outer document in the DOM generated by SmartGWT.

Deffining the hidden iFrame and the callback method in the same canvas as the DynamicForm is correct?

There are some code:

1.- Client:

....
NamedFrame iFrame = new NamedFrame(nombreIFrame);
iFrame.setVisible(false);
iFrame.setWidth("1px");
iFrame.setHeight("1px");
.....
dynamicForm = new DynamicForm();
dynamicForm.setTarget(nombreIFrame);
dynamicForm.setAction("rest/archivo/add");
dynamicForm.setCanSubmit(true);
....

//JSNI
public native void miFuncion() /*-{
    $wnd.alert('Hello');
}-*/;

2.- server 1 (it works)

...
@Produces({ MediaType.TEXT_HTML })
public String upload(...){
...
return "<script>alert('Hello')</script>"
}

3.- Server 2 (it doesn't works)

...
@Produces({ MediaType.TEXT_HTML })
public String upload(...){
...
return "<script>window.parent.document.miFuncion()</script>"
}

Best regards

  • Browser: firefox 20.0
  • O.S: Ubuntu 11.10
  • SmartClient Version: v9.0p_2013-07-14/LGPL Development Only (built 2013-07-14)
¿Fue útil?

Solución

You have to export your method:

var that = this; $wnd.miFunction = $entry(function() { that.@my.app.client.MyClass::miFunction()(); });

See http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html#calling (the example there is for a static method, the one above for an instance method)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top