IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  Validation of multiple input controls on a form

    Posted Fri January 14, 2011 10:58 AM

    We have an input form with a number of input fields, 2 of them need to be validated in such a way that one can be blank on submit but not both.
    So I need a custom validator for each field that checks if the value is blank and if it is blank check if the other field is also blank.
    I have the custom validator working for the control testing for a specific value, but when I test for a blank or null string it won’t work.

    Examples:
    The following works and the exception is thrown as expected when I type “test” into the control and click submit.

    if (value.toString().equalsIgnoreCase("test"))

    But I have tried many different things to get it to test for a blank/null string and can’t get it to work:

    if (value == null)
    if (value.toString().equalsIgnoreCase("")
    if (StringUtils.isBlank(value.toString())
    if (value.toString().length() == 0)

    Any help would be greatly appreciated.


    #MWS-CAF-Task-Engine
    #webMethods
    #webMethods-BPMS


  • 2.  RE: Validation of multiple input controls on a form

    Posted Fri January 14, 2011 04:15 PM

    Hi,
    using a custom validator will not work in this case cause the your custom validator gets called only when the input field has some value.
    Some possible workarounds would be:

    • Add the check in the method (in your view bean) making use of those fields.
    • Add some javascript that makes this validation.
    • (for the lovers of complex solutions :wink: )Add a hidden input for each of the input fields you want to validate. They should have some initial dummy value. In the Blur Client Side event of your input field, empty the value of the corresponding hidden input if the text input has some value and viceversa. So that in the end you validate that both your hidden input fields do not have some value (hope I expressed myself clear enough)

    None of the three is perfect, but I hope it helps you somehow…
    best regards,
    Javier


    #webMethods-BPMS
    #MWS-CAF-Task-Engine
    #webMethods


  • 3.  RE: Validation of multiple input controls on a form

    Posted Mon January 17, 2011 07:51 AM

    Thanks for the response :slight_smile:

    I don’t have a lot of experience with Designer so this is all learning for me.
    How do I access the input field from the java code? Or is it possible to access the fields in the javascript?


    #MWS-CAF-Task-Engine
    #webMethods
    #webMethods-BPMS


  • 4.  RE: Validation of multiple input controls on a form

    Posted Mon January 17, 2011 12:49 PM

    Hi
    you can do both things…

    // get the value in an input control
    var nameValue = CAF.model('#{caf:cid('inputName')}').getValue();
    // Define a variable to a hidden input control
    var hiddenName = CAF.model('#{caf:cid('hiddenInputName')}');
    if (nameValue == null || nameValue === 'undefined' || nameValue == '') {
    hiddenName.setValue("name input is empty");
    } else {
    hiddenName.setValue('');
    }

    In the properties of some controls you will see “Client-Side Events”, where you can add the javascript you want to run on those events. Additionally you have some controls (in the Palette) under the Scripts category where you can add some more custom javascript.

    hope this helps,
    Javier


    #MWS-CAF-Task-Engine
    #webMethods-BPMS
    #webMethods


  • 5.  RE: Validation of multiple input controls on a form

    Posted Tue January 18, 2011 04:57 PM

    Thanks so much, that’s exactly what I needed :slight_smile:


    #MWS-CAF-Task-Engine
    #webMethods
    #webMethods-BPMS