【问题标题】:Gwt Client Validation with editor and request factory使用编辑器和请求工厂进行 Gwt 客户端验证
【发布时间】:2014-12-10 12:22:16
【问题描述】:

我遇到了与 RequestFactory 和 Editors 一起使用的 GWT 客户端验证问题。

编辑代码为:

LocalityRequest localityContext = //create Request 
Locality locality = //Locality Entity Proxy loaded from the server
driver.edit(locality, localityContext); //Edit the proxy
request = localityContext.updateLocality(locality);

保存代码是:

this.localityContext = (LocalityRequest) driver.flush(); //Flush the request
Set<ConstraintViolation<LocalityProxy>> violations = validator.validate(this.locality); //Local validate the object
if (!violations.isEmpty()) {
    Set<ConstraintViolation<?>> sets = new HashSet<ConstraintViolation<?>>(violations);
    driver.setConstraintViolations(sets);
    editLocalityView.setErrors(sets); //give errors to the editors
    return;
}
localityContext.fire(); //else send the request

我的问题是本地验证总是在加载的版本上验证,而不是用户编辑的版本。 我们如何才能获得请求中保存的刷新对象?

谢谢

【问题讨论】:

    标签: java gwt requestfactory gwt-editors gwt-validation


    【解决方案1】:

    您需要缓存/存储已编辑的对象(有关详细信息,请参阅here):

    LocalityRequest localityContext = //create Request 
    Locality locality = //Immutable Locality Entity Proxy loaded from the server
    Locality modifedLocality = ctx.edit(locality); // Create Mutable copy 
    driver.edit(modifedLocality, localityContext); //Edit the mutable proxy
    request = localityContext.updateLocality(modifedLocality);
    

    并在保存代码中:

    this.localityContext = (LocalityRequest) driver.flush(); //Flush the request
    Set<ConstraintViolation<LocalityProxy>> violations = validator.validate(this.modifedLocality); //Local validate the mutable Proxy
    if (!violations.isEmpty()) {
        Set<ConstraintViolation<?>> sets = new HashSet<ConstraintViolation<?>>(violations);
        driver.setConstraintViolations(sets);
        editLocalityView.setErrors(sets); //give errors to the editors
        return;
    }
    localityContext.fire(); //else send the request
    

    【讨论】:

    • 谢谢,通常情况下 ctx.edit() 是由 driver.edit 执行的。如果我们将可变代理传递给驱动程序,驱动程序不会调用编辑方法?
    • AFAIK 当你传递一个可变代理时,驱动程序的编辑调用是一个 nop
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-27
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    相关资源
    最近更新 更多