nl.openedge.baritus.validation.impl
Class RequiredFieldValidator

java.lang.Object
  extended bynl.openedge.baritus.validation.AbstractValidator
      extended bynl.openedge.baritus.validation.AbstractFieldValidator
          extended bynl.openedge.baritus.validation.impl.RequiredFieldValidator
All Implemented Interfaces:
FieldValidator, ValidationRuleDependend

public class RequiredFieldValidator
extends AbstractFieldValidator

Checks for a non-EMPTY input. Use this for fields that should have a not null (empty string) input. Note that as this validator is a field validator, and thus is registered for a single field, it is only fired if a field (e.g. a request parameter) is actually provided. In other words: if an instance of a required field validator was registered for field name 'myprop', but 'myprop' is not part of the request parameters, this validator never fires. Hence, if you want to be REALLY sure that a property of the form is not null, use a form validator (PropertyNotNullValidator). RequiredFieldValidator works fine for most cases where you have a HTML form with a field that should have a non empty value, but that - if a user fools around - does not seriousely break anything when a value is not provided (e.g. you probably have not null constraint in you database as well).

Author:
Eelco Hillenius

Constructor Summary
RequiredFieldValidator()
          Construct using 'input.field.required' as the message prefix.
RequiredFieldValidator(java.lang.String errorMessageKey)
          Construct with errorMessageKey for error message keys.
RequiredFieldValidator(java.lang.String errorMessageKey, ValidationActivationRule rule)
          Construct using errorMessageKey and the activation rule
RequiredFieldValidator(ValidationActivationRule rule)
          Construct using the provided activation rule and 'input.field.required' as the message prefix.
 
Method Summary
 java.lang.String getErrorMessageKey()
          Get key of error message.
 boolean isValid(org.infohazard.maverick.flow.ControllerContext cctx, FormBeanContext formBeanContext, java.lang.String fieldName, java.lang.Object value)
          Checks whether the value is not null, and - if it is an instance of String - whether the trimmed value is not an empty string.
 void setErrorMessageKey(java.lang.String string)
          Set key of error message.
 
Methods inherited from class nl.openedge.baritus.validation.AbstractFieldValidator
getOverrideValue
 
Methods inherited from class nl.openedge.baritus.validation.AbstractValidator
getFieldName, getLocalizedMessage, getLocalizedMessage, getLocalizedMessage, getLocalizedMessage, getValidationActivationRule, removeValidationActivationRule, setErrorMessage, setValidationRule
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface nl.openedge.baritus.validation.ValidationRuleDependend
getValidationActivationRule, removeValidationActivationRule, setValidationRule
 

Constructor Detail

RequiredFieldValidator

public RequiredFieldValidator()
Construct using 'input.field.required' as the message prefix.


RequiredFieldValidator

public RequiredFieldValidator(ValidationActivationRule rule)
Construct using the provided activation rule and 'input.field.required' as the message prefix.

Parameters:
rule -

RequiredFieldValidator

public RequiredFieldValidator(java.lang.String errorMessageKey,
                              ValidationActivationRule rule)
Construct using errorMessageKey and the activation rule

Parameters:
errorMessageKey -
rule -

RequiredFieldValidator

public RequiredFieldValidator(java.lang.String errorMessageKey)
Construct with errorMessageKey for error message keys.

Parameters:
errorMessageKey - errorMessageKey
Method Detail

isValid

public boolean isValid(org.infohazard.maverick.flow.ControllerContext cctx,
                       FormBeanContext formBeanContext,
                       java.lang.String fieldName,
                       java.lang.Object value)
Checks whether the value is not null, and - if it is an instance of String - whether the trimmed value is not an empty string. Note that as this validator is a field validator, and thus is registered for a single field, it is only fired if a field (e.g. a request parameter) is actually provided. In other words: if an instance of a required field validator was registered for field name 'myprop', but 'myprop' is not part of the request parameters, this validator never fires. Hence, if you want to be REALLY sure that a property of the form is not null, use a form validator (PropertyNotNullValidator). RequiredFieldValidator works fine for most cases where you have a HTML form with a field that should have a non empty value, but that - if a user fools around - does not seriousely break anything when a value is not provided (e.g. you probably have not null constraint in you database as well).

Parameters:
cctx - maverick context
formBeanContext - context with bean for this currentRequest
fieldName - field name of parameter
value - the value of this parameter
Returns:
boolean true if not null or empty, false otherwise
See Also:
FieldValidator.isValid(org.infohazard.maverick.flow.ControllerContext, nl.openedge.baritus.FormBeanContext, java.lang.String, java.lang.Object)

getErrorMessageKey

public java.lang.String getErrorMessageKey()
Get key of error message.

Returns:
String key of error message

setErrorMessageKey

public void setErrorMessageKey(java.lang.String string)
Set key of error message.

Parameters:
string - key of error message


Copyright © 2003-2004 Open Edge. All Rights Reserved.