I am using using GWT2.3 with GWTP. Now in this application I need to make a server side call from a non presenter class (So there id no dispatch async instance). Here is my class
public class NameTokenHandler implements ValueChangeHandler<String> {
@Inject
DispatchAsync dispatchAsync;
@Override
public void onValueChange(ValueChangeEvent<String> event) 开发者_JAVA技巧{
if (event != null) {
String nameToken = event.getValue();
if(dispatchAsync!=null)
{
System.out.println("yes");
} else {
System.out.println("No");
}
History.newItem(nameToken);
}
}
}
Here dispatchAsync is always null. I am getting from where it should be initialized so that I can make a server side call. If there is any other way then please let me know. Thanks in advance.
You need to inject the NameTokenHandler
, so your dispatcher will be injected too.
public class C {
private NameTokenHandler handler;
@Inject
public C(NameTokenHandler handler) {
this.handler = handler;
}
}
This way the handler will be injected to the C
class, and your dispatcher will also be injected in the NameTokenHandler
. BTW you might need to have a constructor in NameTokenHandler
that follows the same pattern (DispatchAsync
as a parameter).
精彩评论