2

我有一个 webMethods CAF 任务,它有一个带有保存按钮和提交按钮的大表单。表单上的许多元素都有验证。用户需要能够点击保存并将表单提交到后端模型,以便可以将其保存为任务数据,而无需触发验证。点击提交应该触发验证。

如何配置页面来执行此操作。这是一个正常的要求,我被卡住了!

4

2 回答 2

2

这不是很有趣。

  1. 给你的保存按钮一个漂亮的 ID。说,保存按钮
  2. 在您的 Java 代码中创建一个返回布尔值的 getter。在其中,如果按钮的 ID 是提交的字段之一,则返回 true,否则返回 false:

    private boolean validationRequired() {
        return mapValueEndsWith((Map<String, String>)getRequestParam(),
            new String[] {
                "saveButton",           // Your save button
                "anotherButton",        // Perhaps another button also shouldn't validate
                "myForm:aThirdButton"   // perhaps you want to be specific to a form
            });
    }
    
  3. 在每个需要的字段中,除了 Save 之外,将 Validation->required 属性绑定到您的 validationRequired getter。

而已!屏幕上有很多字段非常乏味,但它确实有效。

PS什么是mapValueEndswith?只是一个实用程序;为了紧凑而删除了空格:

private boolean mapValueEndsWith(Map<String, String> haystack, String[] needles) {
    for(String needle : needles) if(mapValueEndsWith(haystack, needle)) return true;
    return false;
}

private boolean mapValueEndsWith(Map<String, String> haystack, String needle) {
    for(String value : haystack.values()) if(value.endsWith(needle)) return true;
    return false;
}
于 2015-03-31T12:01:54.553 回答
-2

正如我看到所提供的方法,仅当表单仅包含字符串类型字段时才有效。如果有任何其他数据类型(如整数、浮点数、数据时间)映射到 UI 字段并使用转换,那么如果在这些字段中输入错误数据,则可能会失败。

于 2015-04-02T11:37:33.987 回答