Ste*_*vko 23 java gwt google-app-engine dao
我有一个新编码的GWT/GAE应用程序,它在客户端上使用RequestFactory和Editors,在后面使用自定义Objectify DAO服务.
flush()然后persist()路径在成功时工作正常.客户端JSR 303的工作原理也可以预期.
我的问题是如何触发服务器警告/错误并处理UI更新?
我在http://turbomanage.wordpress.com/2010/02/09/generic-dao-for-objectify-2/上使用Chandler的Obneric DAO for Objectify 2
我的gwt活动是调用persist(myProxy).fire(new Receiver <>)
我的dao代码为业务逻辑情况抛出了IllegalArgumentException和其他RuntimeExceptions,例如"找到重复的电子邮件地址 - 想要登录?"
Receiver <>.onSuccess()可以很好地跟踪成功的结果.Receiver <>.onFailure()和Receiver <>.onViolation()都不报告RuntimeExceptions.
(更正:正在为服务器端异常调用onFailure())
有一个更好的方法吗?DAO应抛出哪些异常,以便onViolation()或onFailure()报告错误?编辑器应如何处理并从异常中恢复?
我发现最通用的命令序列是
\n\nvoid start() {\n // Either get p\n context1.get(..).to( new Receiver<P> { onSuccess(P resp){p = resp;} ... }).fire();\n // OR create p\n p = context2.create( P.class );\n // Then save p\n req = context2.persist(p).to( new Receiver<P>{ /* note do not use context1 */\n onViolation(...) { /*JSR 303 handler*/ };\n onFailure( error ) { /* handle */ error.getMessage() }; \n onSuccess(X x) { /* whatever persist() returns handler */ }; } ); \n // drive editor with p\n driver.edit( p, req); \n}\n\n....\nvoid onSave() { \n // editor\n ctxt = driver.flush() /* note ctxt == context2 */\n if ( driver.hasErrors() ) { /*JSR 303 handler*/};\n // RF\n ctxt.fire();\n}\nRun Code Online (Sandbox Code Playgroud)\n\n\n\n\n\nThomas Broyer \n onFailure 应该包含您在服务器端抛出的\n 异常的 getMessage()。
\n\n您可以通过向 RequestFactoryServlet 提供您自己的 ExceptionHandler 来调整它(扩展它并使用其带有 ExceptionHandler 的构造函数)。
\n\n仅当您的实体未通过 JSR-303 Bean 验证(在调用任何服务方法之前进行检查)时,才会调用 onViolation。
\n\n如果您想\n“捕获”客户端代码中的故障,\n您必须为\n persist()服务方法添加一个接收器:
\n
\n context.persist(p).to(new Receiver\xe2\x80 \xa6
| 归档时间: |
|
| 查看次数: |
3010 次 |
| 最近记录: |