Thursday, January 22, 2015

RequestFactory - ValueProxy is null

Hi,

I have written a small program to test the RequestFactory. I have a TestEntity class and a TestValue class on the server and corresponding TestEntityProxy and TestValueProxy on the client.

public class TestEntity {

private static long staticIDpool = 0;
private Long id;
private String testString;
private TestValue testValue; 
public TestEntity() {
super();
id = Long.valueOf(staticIDpool++);
}

public Long getId() {
return id;
}

public String getTestString() {
return testString;
}
public void setTestString(String testValue1) {
this.testString = testValue1;
}

public TestValue getTestValue() {
return testValue;
}
public boolean setTestValue(TestValue testValue) {
this.testValue = testValue;
return true;
}
@Override
public String toString() {
return "Entity ["+testString+", "+testValue+"]";
}
}

public class TestValue {

private String s1;
public TestValue() {
s1 = "default1 (set on server)";
}
public String getS1() {
return s1;
}
public boolean setS1(String s) {
this.s1 = s;
return true;
}

@Override
public String toString() {
return "TestValue ["+s1+"]";
}
}

The proxies
@ProxyFor(value = TestEntity.class, locator = EntityLocator.class)
public interface TestEntityProxy extends EntityProxy {
 
String getTestString();
 
TestValueProxy getTestValue();
}

@ProxyFor(TestValue.class)
public interface TestValueProxy extends ValueProxy {
String getS1();
}

The EntityDAO and Locators
public class EntityDAO {
private final static Logger LOG = Logger.getLogger("");
private static EntityDAO singletonInst;
private EntityDAO(){} // use getInstance() to get the singleton instance
public static EntityDAO getInstance(){
if(singletonInst==null)singletonInst = new EntityDAO();
return singletonInst;
}

public TestEntity createDefaultTestEntity(){
LOG.info("server createDefaultTestEntity()");

TestValue v = new TestValue();
v.setS1("testVALString (set on server)");

TestEntity e = new TestEntity();//v, "teststring set on server");
e.setTestString("teststring set on server");
e.setTestValue(v);
LOG.info("server created! "+e);
return e;
}
}

public class EntityLocator extends Locator<TestEntity, Long> {

@Override
public TestEntity create(Class<? extends TestEntity> clazz) {
return EntityDAO.getInstance().createDefaultTestEntity();
}

@Override
public TestEntity find(Class<? extends TestEntity> clazz, Long id) {
return null;
}

@Override
public Class<TestEntity> getDomainType() {
return TestEntity.class;
}

@Override
public Long getId(TestEntity domainObject) {
return domainObject.getId();
}

@Override
public Class<Long> getIdType() {
return Long.class;
}

@Override
public Object getVersion(TestEntity domainObject) {
return null;
}

}

public class EntityDaoLocator implements ServiceLocator {
public Object getInstance(Class<?> clazz) {
return EntityDAO.getInstance();
}

}

My RequestFactory
public interface TestRequestFactory extends RequestFactory {

@Service(value = EntityDAO.class, locator = EntityDaoLocator.class)
public interface EntityRequestContext extends RequestContext{
Request<TestEntityProxy> createDefaultTestEntity();
}
public EntityRequestContext getEntityRequestContext();
}

And finally the entryPoint
public void onModuleLoad() {

TestRequestFactory requestFactory = GWT.create(TestRequestFactory.class);
requestFactory.initialize(new SimpleEventBus());

requestFactory.getEntityRequestContext().createDefaultTestEntity().fire(new Receiver<TestEntityProxy>() {

@Override
public void onSuccess(TestEntityProxy e) {
TestValueProxy v = e.getTestValue();
String vs = "null";
if(v!=null){
vs = v.getS1();
}
Window.alert(e.getTestString()+" / "+vs);
}
@Override
public void onFailure(ServerFailure error) {
try{
super.onFailure(error);
}catch(Exception e){
Window.alert(error.getMessage());
}
}
});
}

The Text in the alert dialog is "teststring set on server / null". So the String is transmitted to the client but the test vale set in the entity is null. On server side the toString of the entity (log message at the end of createDefaultTestEntity()) returns server created! Entity [teststring set on server, TestValue [testVALString (set on server)]]
So the testValue is set in here.

Please, can anybody tell me what I did wrong. Cause at the moment I can't see the difference to the tutorials I read.
Thanks alot!! 
Andy

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment