2

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!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Rob Grant
  • 7,239
  • 4
  • 41
  • 61
  • Where do you have your validation implemented? – Aritz Jan 09 '14 at 13:21
  • It's server-side validation, just configured in webMethods Designer. Required=true is the main one. I think it just runs a built-in validator in the Process Validations phase. – Rob Grant Jan 09 '14 at 13:23
  • Are you able to perform it with `required="true"`? – Aritz Jan 09 '14 at 13:42
  • The validation works, but the save doesn't. If I set immediate=true on the Save button, it doesn't throw validation errors, but it also replaces the new values from the form with the previous ones from the backend. – Rob Grant Jan 09 '14 at 13:59
  • I've worked this out and forgot to reply. Will document here. It's not very pretty. – Rob Grant Jul 22 '14 at 07:48
  • Is this acceptable as dupe? http://stackoverflow.com/questions/2780903/jsf-how-to-temporary-disable-validators-to-save-draft/ – BalusC Mar 31 '15 at 13:01
  • @BalusC maybe in terms of similar question, but I prefer my answer :) What do you think from that POV? – Rob Grant Apr 14 '15 at 07:24

2 Answers2

2

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;
}
Rob Grant
  • 7,239
  • 4
  • 41
  • 61
-2

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.

  • This should be a _comment_, not an _answer_. Anyway. Agreed, but as long as you have clientside validation on it should work fine. I might be able to expand the answer to include how to cope with conversions etc. – Rob Grant Apr 05 '15 at 03:05
  • I know this is a comment but just to make a note a User needs 50 reputation to comment. When I did this I don't have that reputation. – Raghava Rudrakanth P V May 27 '15 at 06:07