Failure at loading GWT library - gwt

I am trying to deploy a bigger GWT project to start working on it. After several problems I finally ran into the following, which I am not able to solve:
Here is a random piece of code:
service.getSuggestionOracle(this.suggestionString.getText(), new AsyncCallback<List<Entity>>() {
#Override
public void onSuccess(List<Entity> result) {
suggestionString.setStyleName("searchInput");
processSuggestionOracle(result);
}
#Override
public void onFailure(Throwable caught) {
suggestionString.setStyleName("searchInput");
GWT.log("Suggestion fails.");
}
});
Eclipse complains about the two functions onSuccess and onFailure that:
The method onSuccess(List<Entity>) of type new AsyncCallback<List<Entity>>(){} must override a superclass method
Indeed when I hover over the: new AsyncCallback<List<Entity>>() statement, it tells me that If an RPC is successful, then onSuccess(Object) is called, otherwise onFailure(Throwable) is called.
I conclude that there IS a superclasses with declarations for onSuccess and onFailure, but the compiler doesn't find it.
I use GWT-2.4.0 and the GWT library is added to the classpath.
The code above is just a random example, there are about 150 similar errors all over the
project. Additionally, there are several imports like com.xind.gwt.dom.client.DOM,
that can not be resolved.
Does anybody have an idea what I am missing here?

There are two possibilities that I could think of:
you haven't extended RemoteServiceServlet on the server implementation.
or
In this code,
public void onSuccess(List result) {
}
you have List as the returned object. Is this a list of objects of a user-defined class or java datatype? If the list is a user-defined type, then you must serialize the corresponding class by implementing java.io.serializable;

Related

Generate inline class for method call parameter in Eclipse

When calling a method that expects an implementation of a specific class, how can I make eclipse write this boring piece of code for me?
In the following example, only the first line needs to be writen by a human:
o.call(
new MyFunction<List<String>>()
{
#Override
public void call(List<String> lst) throws Exception {
}
}
Type o.call(new MyF then Ctrl+Space and Eclipse should offer to complete the anonymous class skeleton for you. You might not even need the new MyF part, depending on how unambiguous the context is.

Add new Constructor to an existing Java Class via AspectJ

Trying to clean up some nasty code, for which we dont have the source code. Imagine something like this:
public class Driver{
private String paramA;
private String paramB;
new Driver(HugeAndOverbloatedObject object)
{
paramA = object.getSubObject4711().getParamX();
paramB = object.getSubObject4712().getParamY();
}
}
This third library has this all over the place: tight coupling via constructors, eventhough the classes are hardly related. The rude combination of private members and forced constructor inheritance make the extension of the code virtually impossible without creating "sloppy" constructor parameter objects.
So I am trying to manipulate the classes via AspectJ and compile time weaving, so I can slim down on the constructors, to something like this:
Driver driver = new Driver("paramA", "paramB");
I think this should be possible, and I have made some progress. If I have something like this:
public aspect NewConstructor {
Driver.new(String parameterA, String parameterB){
//New Constructor Code
}
}
and run this through the weaver I actually find a new constructor in the driver, but not quite as I expected.
Issue: Unexpected third Parameter in the woven class
I was hoping I can invoke it with two parameters:
new Driver("paramA", "paramB")
Instead I need to invoke it with three parameters:
new Driver("paramA", "paramB", new NewConstructor())
Why do I need to instantiate a new instance of the aspect and pass it as an argument? Can this be prevented?
Something odd is going on here. You should not need to add the aspect as a third argument to the constructor. In fact, when I try this myself using the following class and aspect, I do not get any compile errors:
Java class:
package pack;
public class Driver {
public static void main(String[] args) {
new Driver("paramA", "paramB");
}
}
Aspect:
package pack;
public aspect NewConstructor {
public pack.Driver.new(String parameterA, String parameterB){
}
}
Are your Java class and aspect in different projects? Are you using an aspect path and/or in path? Are you using load time weaving?
If after doing a full build of your project you still see the probem, it's worth raising a bug for AspectJ.

Why can't JavascriptObject's runtime null pointer be detected?

After some debugging,I found "com.google.gwt.event.shared.UmbrellaException:One or
more exceptions caught, see full set in UmbrellaException#getCauses' when calling method: [nsIDOMEventListener::handleEvent]"(in web model) is caused by runtime null pointer.Question is why this kind of runtime null pointer exception didn't got thrown out under host model.Actually,blow code won't thrown out any exception and even got alert popup in my laptop(gwt 2.4+java 7 64bit+ubuntu 12.04 64bit+eclipse 3.7).Anybody knows how to enforce eclipse throw out exception whenever a runtime null on JavascriptObject pointer occurs.
public class GWTTest implements EntryPoint
{
public static class JsObj extends JavaScriptObject
{
protected JsObj()
{
}
public final native void setValue(String Value)/*-{
this.Value=Value;
alert(Value);
}-*/;
}
public void onModuleLoad()
{
JsObj jsObj = null;
jsObj.setValue("val");
}
}
The compiler performs a number of optimizations to transform GWT/Java into Javascript.
Types and methods are made final - this allows later steps to understand which methods need to be dispatched as normal, and which can be made static, just calling a single implementation.
Methods are made static, where possible, which allows methods to be inlined
Where possible and reasonable, methods are inlined
That said... When I compile your sample, the body of onModuleLoad() is optimized out to this:
null.nullMethod();
This is the GWT compiler's way of saying 'this will never work' - it notices that the value is always null, and so the method can't be invoked on it. But in Dev Mode, apparently the null object is left pointing at the window object in JavaScript. This is filed at http://code.google.com/p/google-web-toolkit/issues/detail?id=6625 in the GWT project.
If you need to make sure you don't act on a null, test for null before calling the method - it'll get optimized out if, in a test like yours, the value is always null. Runtime exceptions shouldn't be used for controlling code anyway, so you should never rely on a NullPointerException to do anything in your code.

GWT development mode is quiet

I'm developing a project with GWT for quite some months but since two weeks or so i get no more feedback in the jetty development mode window when an error occures...
How could that come?? Could it be caused by some missconfiguration of the logging module? Some errors appear on the console of the started jetty application as [INFO].
Try CCleaner Software and clean all Recent files, browser Cache, Temporary files etc. Then just restart eclipse or better restart the entire System. Also, check if you have GWT.log("MESSAGE") method called for Errors/Exceptions.
The strange behaviour with GWT can happen if:
You have "server" (not included source code) class
You have only import to server class
One of your bean used to communication by service is not serializable (or not extends IsSerializable) or any of it attributes is not serializable
Your bean used to communication by service do not have not parameters constructor (or any of parent class)
Your bean used to communication by service has final field
I had almost all from this when I searched why my code is broken. I did not included all cases of course :)
Update
In our project we extends AsyncCallback
public abstract class MyAsyncCallback<T> implements AsyncCallback<T> {
#Override
public final void onFailure(Throwable caught) {
yourLogger.log(caught);
onFailureDefault(caught);
}
protected abstract void onFailureImpl(Throwable caught);
}
You has to replace all your AsyncCallback with this. Now you have control on errors. Sometimes there are suppressed by wrong error handling.
See also GWT.setUncaughtExceptionHandler(GWT.UncaughtExceptionHandler handler)

How do I get server side initialization code to run when building GWT Test Cases?

I'm using GWT 2.4. I have a number of test files that extend GwtTestCase. My question is, how and where do I place code so that the server side initializes some data before my tests run?
I tried creating a simple servlet ...
public class PopulateCacheServlet extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
try {
PopulateCache.addTestEntriesToCache();
System.out.println("Dummy entries written to cache.");
} catch (Exception e) {
e.printStackTrace();
}
} // init
}
and adding its definition to my module's .gwt.xml file ...
<servlet path="/populatecache" class="com.myco.clearing.web.PopulateCacheServlet" />
but I'm noticing that this init method is never called.
You could simply add a static code block to your PopulateCacheServlet class or initialize the class in the constructor. Static code block if you want to run the method just once and only once (per JVM). Initialization in the constructor if you want to set up each servlet separately. Okay that is not the most beautiful solution, but since it is a test class...
The other option is you call the initialize method from the GwtTestCase. You can use a method annotated with #BeforeClass to call the servlet's init method once before the test is running. Of course you have to make your servlet a GWT RemoteServlet in order for this to work. Otherwise the servlet is not easily accessible from GWT code.