java - 如何使用 GWT 编辑器框架进行验证?

标签 java gwt editor uibinder gwt2

我正在尝试与 GWT 2.1.0 的新 GWT 编辑器框架集成。我还想将我的验证检查添加到框架中。但是,我正在努力寻找如何做到这一点的体面示例。

目前我有以下代码:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
    xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:e="urn:import:com.google.gwt.editor.ui.client">
    <ui:with type="be.credoc.iov.webapp.client.MessageConstants"
        field="msg" />
    <g:HTMLPanel>
        <e:ValueBoxEditorDecorator ui:field="personalReference">
            <e:valuebox>
                <g:TextBox />
            </e:valuebox>
        </e:ValueBoxEditorDecorator>
    </g:HTMLPanel>
</ui:UiBinder> 

对于我的编辑:

public class GarageEditor extends Composite implements Editor<Garage> {

    @UiField
    ValueBoxEditorDecorator<String> personalReference;

    interface GarageEditorUiBinder extends UiBinder<Widget, GarageEditor> {
    }

    private static GarageEditorUiBinder uiBinder = GWT.create(GarageEditorUiBinder.class);

    public GarageEditor() {
        initWidget(uiBinder.createAndBindUi(this));
    }

}

我必须在什么时候调用我的 validator 以及如何与它集成?

更新:

我实际上正在寻找一种方法来检索以属性路径为键并以编辑器为值的 map 。委托(delegate)上有一个路径字段,但这不是编辑对象内的路径,而是编辑器类中的路径。

有人知道是否可以做这样的事情吗?

最佳答案

用 contstrants 注释你的 bean(见 Person.java)

public class Person {
  @Size(min = 4)
  private String name;
}

使用标准验证 Bootstrap 在客户端获取 validator 并验证您的对象(参见 ValidationView.java)

Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
Set<ConstraintViolation<Person>> violations = validator.validate(person);

按照此模式为要在客户端验证的对象创建 validator 。 (见 SampleValidatorFactory.java)

public final class SampleValidatorFactory extends AbstractGwtValidatorFactory {

  /**
   * Validator marker for the Validation Sample project. Only the classes listed
   * in the {@link GwtValidation} annotation can be validated.
   */
  @GwtValidation(value = Person.class,
      groups = {Default.class, ClientGroup.class})
  public interface GwtValidator extends Validator {
  }

  @Override
  public AbstractGwtValidator createValidator() {
    return GWT.create(GwtValidator.class);
  }
}

包括您的验证提供程序的模块。在您的 gwt 模型文件中添加替换标记,告诉 GWT 使用您刚刚定义的 validator (参见 Validation.gwt.xml)

<inherits name="org.hibernate.validator.HibernateValidator" />
<replace-with
    class="com.google.gwt.sample.validation.client.SampleValidatorFactory">
    <when-type-is class="javax.validation.ValidatorFactory" />
</replace-with>

Source

关于java - 如何使用 GWT 编辑器框架进行验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4098579/

相关文章:

java - 使用 Rectangle.Intersects 进行碰撞检测会导致对象到表面 "stick"(Java)

java - 配置中的属性占位符

css - 既然已经有了 CSS 布局,为什么还需要在 GWT 中使用布局面板?

jquery - 我疯了吗? (如何)我应该创建一个jQuery内容编辑器?

java - 使用 cssSelector 清除 Chrome 浏览器的浏览数据时如何与 #shadow-root (open) 中的元素进行交互

spring - GWT - RemoteService 接口(interface)和 Spring - 如何获取 HttpSession?

java - 如何对 "toString()"GWT EntityProxy derivatives进行日志记录和调试?

xml - 有没有可以帮助某人创建基于 Relax NG 模式的 XML 文档的应用程序?

java - 在调试期间禁用/防止编辑 (Eclipse)

java - 错误 StatusLogger Log4j2 找不到日志记录实现