Question

I have a webMethods CAF task that has a big form with a save button and a submit button. Many elements on the form have validation. The user needs to be able to hit Save and have the form submitted to the back end model so it can be saved as task data, without firing validation. Hitting Submit should fire validation.

How can I configure the page to do this. It's such a normal requirement, and I'm stuck!

Was it helpful?

Solution

It's not much fun.

  1. Give your Save button a nice ID. Say, saveButton
  2. Create a getter in your Java code that returns a boolean. Inside it, return true if the button's ID is one of the submitted fields, otherwise 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. In every field that should be required, except on Save, bind the Validation->required attribute to your validationRequired getter.

That's it! Very tedious with a lot of fields on the screen, but it works.

P.s. what's mapValueEndswith? Just a utility; removed whitespace for compactness' sake:

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;
}

OTHER TIPS

As I see the approach provided, works only if the form contains only string type fields. If there are any other data types like integer, float, data-time are mapped to UI fields and conversion is used then this might fail if wrong data is entered in those fields.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top