我有一个新编码的GWT/GAE应用程序,该应用程序在客户端上使用RequestFactory和Editors,在背面使用自定义Objectify DAO服务。如果成功,则flush()然后persist()路径会正常工作。客户端JSR 303也可以正常工作。我的问题是如何触发服务器警告/错误并处理UI更新?我在使用Chandler的Objectify 2的通用DAO http://turbomanage.wordpress.com/2010/02/09/generic-dao-for-objectify-2/我的gwt Activity 正在调用persist(myProxy).fire(new Receiver )我的dao代码针对业务逻辑情况(例如“找到重复的电子邮件地址-想要登录?”)抛出IllegalArgumentException和其他RuntimeExceptions。Receiver 。onSuccess()可以很好地跟踪成功的结果。Receiver 。onFailure()和Receiver 。onViolation()均不会报告RuntimeExceptions。 (服务器端异常正在更正:onFailure())有一个更好的方法吗?DAO应该抛出哪些异常,以便onViolation()或onFailure()报告错误?编辑者应如何处理异常并从异常中恢复? 最佳答案 我发现最通用的命令序列是void start() { // Either get p context1.get(..).to( new Receiver<P> { onSuccess(P resp){p = resp;} ... }).fire(); // OR create p p = context2.create( P.class ); // Then save p req = context2.persist(p).to( new Receiver<P>{ /* note do not use context1 */ onViolation(...) { /*JSR 303 handler*/ }; onFailure( error ) { /* handle */ error.getMessage() }; onSuccess(X x) { /* whatever persist() returns handler */ }; } ); // drive editor with p driver.edit( p, req);}....void onSave() { // editor ctxt = driver.flush() /* note ctxt == context2 */ if ( driver.hasErrors() ) { /*JSR 303 handler*/}; // RF ctxt.fire();}根据下面http://groups.google.com/group/google-web-toolkit/browse_thread/thread/da863606b3893132/96956661c53e1064?hl=en的对话摘录 Thomas Broyer onFailure should containg the getMessage() of the exception you threw on the server side. You can tweak it by providing your own ExceptionHandler to the RequestFactoryServlet (extend it and use its constructor taking an ExceptionHandler). onViolation will only be called if your entities do not pass JSR-303 Bean Validation, which is checked before calling any service method. If you want to "catch" the failure in clidnt code, you have to add a Receiver for the persist() service method: context.persist(p).to(new Receiver…关于java - 处理GWT RequestFactory服务器错误响应,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5277084/ 10-14 11:45