I'm trying to persist a simple class with objectify but without success.
Apologies for the long post but I think more information is better than less.
I followed the example by David M. Chandler in:
http://turbomanage.wordpress.com/2011/03/25/using-gwt-requestfactory-with-objectify/
But I keep getting NullPointerException.
I don't know what I'm doing wrong but the classes I use are the following:
My proxies, DatastoreObjectProxy:
@ProxyFor(value = DatastoreObject.class, locator = ObjectifyLocator.class)
public interface DatastoreObjectProxy extends EntityProxy{
Long getId();
void setId(Long id);
Integer getVersion();
void setVersion(Integer id);
}
and BeingProxy:
@ProxyFor(value = Being.class, locator = ObjectifyLocator.class)
public interface BeingProxy extends DatastoreObjectProxy {
String getName();
void setName(String name);
String getFiscalNumber();
void setFiscalNumber(String fiscalNumber);
}
and my request factory:
public interface MyRequestFactory extends RequestFactory{
@Service(value = BeingDao.class, locator = DaoServiceLocator.class)
interface BeingRequestContext extends RequestContext {
Request<List<BeingProxy>> listAll();
Request<Void> save(BeingProxy being);
Request<BeingProxy> saveAndReturn(BeingProxy being);
Request<Void> removeBeing(BeingProxy being);
}
BeingRequestContext beingRequestContext();
}
Finally my UI uses the following code to create and retrieve a Being entity:
@UiHandler("btnAdd") void onBtnAddClick(ClickEvent event) {
//Validate name
//TODO warn user if invalid
if (txtName==null||txtName.getText().equals("")){return;}
String n = txtName.getText();
//Validate fiscal number
//TODO warn user if invalid
if (txtFiscalNumber==null||txtFiscalNumber.getText().equals("")){return;}
String fn = txtFiscalNumber.getText();
BeingRequestContext reqCtx = rf.beingRequestContext();
final BeingProxy being = reqCtx.create(BeingProxy.class);
being.setName(n);
being.setFiscalNumber(fn);
Request<BeingProxy> saveRequest = reqCtx.saveAndReturn(being);
saveRequest.fire(new Receiver<BeingProxy>(){
@Override
public void onSuccess(BeingProxy response) {
addToList(response);
}
});
That throws the previous mentioned exception.
I've noted that the server code is note executed. So I guess the problem is in the request factory or in the client. But I triple checked the code and did not find anything wrong.
Thank you for your time.
Best Regards.
I figured this one out. I wasn't initializing the request factory properly. I had to initialize it with an event bus:
final MyRequestFactory rf = GWT.create(MyRequestFactory.class);
EventBus eventBus = new SimpleEventBus();
rf.initialize(eventBus);