本文介绍了带编辑器框架的GWT验证器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 有没有人意识到编辑器和jsr 303验证如何与GWT 2.3 一起使用?验证API已添加到gwt sdk。但我无法使用编辑器框架验证实体。无论是什么,我都不会从客户端或服务器端抛出错误。 以下是一段代码片段: public class P { public P(){} @Size(min = 4)私人字符串名称; public void setName(String name){ this.name = name; } public String getName(){ return name; } } PEditor public class PEditor extends Composite implements< P> { private static PEditorUiBinder uiBinder = GWT.create(PEditorUiBinder.class); interface PEditorUiBinder扩展UiBinder< Widget,PEditor> {} @UiField TextBox名称; public PEditor(){ initWidget(uiBinder.createAndBindUi(this)); } } PEditor pEditor; 接口Driver扩展了SimpleBeanEditorDriver< P,PEditor> {} 驱动程序驱动程序= GWT。<驱动程序>创建(Driver.class); public void onModuleLoad(){ pEditor = new PEditor(); driver.initialize(pEditor); P p = new P(); driver.edit(p); pEditor.name.setText(G); driver.flush(); if(driver.hasErrors()){ List< EditorError> errors = driver.getErrors(); for(EditorError error:errors){ System.out.println(error.getMessage()); $ / code> 感谢您的帮助 解决方案验证API,至少2.3,不会为你构建客户端代码 - 它是一种可以集成在服务器上的工具,以便在某些情况下让服务器反吐错误。 调用 EditorDriver.hasErrors()只是用来检查是否有代码告诉本地代理是否有错误 - 客户端验证可以通过这个来实现。 现在最自动的情况是使用RequestFactory时 - 如果您的服务器classpath上有javax.validation jar(api和sources)以及验证库(hibernate- validator和apache的bval是两个这样的库),Receiver回调函数将调用 onViolation 。 使用RequestFactory从服务器获取 RequestF的违规然后可以使用actoryEditorDriver 将错误推送到UI,尽管使用 HasEditorErrors 编辑器实例和包装器,如 ValueBoxEditorDecorator ,或者仅当调用 onViolation 时通过某种机制(alert,banner,debug sys.out.println等)通知用户。 如果使用RPC,您可以自行运行服务器验证,并且(从2.3开始)调用 driver.setConstraintViolations 与验证过程在服务器上生成的 ConstraintViolation 对象。 Have anybody realized how editors and jsr 303 validation work with GWT 2.3coming? Validation API was add to gwt sdk. But I am unable to validate entities using the editor framework. No matter whatI do the errors are never thrown from client side or server side.Here is a code snippet:public class P { public P() {} @Size(min=4) private String name; public void setName(String name) { this.name = name; } public String getName() { return name; }}PEditorpublic class PEditor extends Composite implements Editor<P> { private static PEditorUiBinder uiBinder = GWT.create(PEditorUiBinder.class); interface PEditorUiBinder extends UiBinder<Widget, PEditor> {} @UiField TextBox name; public PEditor() { initWidget(uiBinder.createAndBindUi(this)); }} PEditor pEditor; interface Driver extends SimpleBeanEditorDriver<P, PEditor> {} Driver driver = GWT.<Driver> create(Driver.class); public void onModuleLoad() { pEditor = new PEditor(); driver.initialize(pEditor); P p = new P(); driver.edit(p); pEditor.name.setText("G"); driver.flush(); if(driver.hasErrors()) { List<EditorError> errors = driver.getErrors(); for (EditorError error : errors) { System.out.println(error.getMessage()); } } }Thanks for your help 解决方案 The Validation API, at least as of 2.3, doesn't build client side code for you – it is a tool that can be integrated on the server to make your server spit back errors in certain cases.The call to EditorDriver.hasErrors() is just to check if any code has told the local delegates if there are errors – client-side validation can be implemented through this.The most automatic case right now is when using RequestFactory - if you have the javax.validation jar (both api and sources) on your server classpath as well as a validation library (hibernate-validator and apache's bval are two such libraries), the Receiver callback will have onViolation called.With RequestFactory being used to get violations from the server, the RequestFactoryEditorDriver can then be used to push errors to the UI, though the use of HasEditorErrors editor instances and wrappers, like ValueBoxEditorDecorator, or just by notifying the user through some mechanism (alert, banner, your debug sys.out.println, etc) when onViolation is called.If using RPC, you can run the server validations on your own, and (as of 2.3) call driver.setConstraintViolations with the ConstraintViolation objects generated on the server from the validation process. 这篇关于带编辑器框架的GWT验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-09 02:24