hi..
assume i wanna be client agnostic, meaning the client for gwt app maybe gwt
client,flex/sliverlight what not.
so i can't use requestFactory, and i need a standard wire protocol, so how
about json?
can i use AutoBean in a servlet like so:?
final EntityManagerFactory emf =
Persistence.createEntityManagerFactory("hr");
final EntityManager em = emf.createEntityManager();
final String id = request.getParameter("id");
final Employee e= em.find(Employee.class, Long.valueOf(id));
final AutoBeanVisitor v=new AutoBeanVisitor() {
@Override
public boolean visitValueProperty(final String
propertyName,final Object value, final PropertyContext ctx) {
if(ctx.canSet()) {
try {
final Object field =
ReflectionHelper.getField(Employee.class, e, propertyName);
ctx.set(field);
} catch (final Exception e2) {
System.out.println(e2);
}
}
return super.visitValueProperty(propertyName, value, ctx);
}
};
final AutoBean<IEmployee> abEmployee = F.employee();
abEmployee.accept(v);
final Splittable encodedEmployee = AutoBeanCodex.encode(abEmployee);
final String asString = encodedEmployee.toString();
final PrintWriter writer = response.getWriter();
writer.write(asString);
writer.flush();
writer.close();
em.close();
emf.close();
and then in a gwt client write like this:
final String url = "http://127.0.0.1:8888/EmployeeInfo?id=200";
final RequestBuilder builder = new
RequestBuilder(RequestBuilder.GET, URL.encode(url));
try {
final Request request = builder.sendRequest(null, new
RequestCallback() {
@Override
public void onError(final Request request, final Throwable
exception) {
System.out.println(exception);
}
@Override
public void onResponseReceived(final Request request, final
Response response) {
if (response.getStatusCode()==Response.SC_OK) {
final String text = response.getText();
final AutoBean<IEmployee> decode =
AutoBeanCodex.decode(F, IEmployee.class, text);
final IEmployee as = decode.as();
driver.edit(as);
} else {
System.out.println(response.getStatusCode());
}
}
});
} catch (final RequestException e) {
System.out.println(e.toString());
}
thus i still get the benefits of a gwt editor, and not be bound to the wire
protocol of requestFactory (yes i know it's also json, but it's an
end-to-end thingy)
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-web-toolkit/-/1gQOYmWRToUJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.