You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Val Blant (JIRA)" <de...@myfaces.apache.org> on 2006/05/04 19:41:18 UTC

[jira] Created: (MYFACES-1297) Validators are not executed on empty input fields

Validators are not executed on empty input fields
-------------------------------------------------

         Key: MYFACES-1297
         URL: http://issues.apache.org/jira/browse/MYFACES-1297
     Project: MyFaces Core
        Type: Bug

  Components: General  
    Versions: 1.1.2    
 Environment: Doesn't matter. It's a logic bug.
    Reporter: Val Blant


There is a problem in the code of javax.faces.component.UIInput.validateValue method.

This part is wrong:
        if (!empty)
        {
            _ComponentUtils.callValidators(context, this, convertedValue);
        }

Here is why. 
The above will work if you use required="true" attribute on your input fields in order to check if the field is empty. However, the 'required' attribute cannot be used if you want to make the validation rules a bit more complex. For example, if you want to configure the level of validation for each field on per button basis (skip validation when certain buttons on the page are pressed, do partial validation on others or do the full validation on the rest). This is easily achieved by writing custom validators that check for certain request parameters and do the validation accordingly. This is a lot like the solution described here: http://wiki.apache.org/myfaces/OptionalValidationFramework

The problem is that such a validation framework must have its own RequiredValidator, if it wants to check for empty values. However, due to the code in UIInput.validateValue method, there is no way to actually run your custom validators if the value is empty. That one line of code breaks mine and http://wiki.apache.org/myfaces/OptionalValidationFramework implementations.

As a workaround I had to write some ugly code to register a 2 phase listeners around the Validate phase, that will replace empty input values with a sentinel string before validation and then remove it after.

I would think that UIInput should run validators regardless of whether the value is empty or not and rely on validators to properly handle null values.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira