org.apache.myfaces.trinidad.validator

## Class ByteLengthValidator

- java.lang.Object
- - org.apache.myfaces.trinidad.validator.ByteLengthValidator

- All Implemented Interfaces:
    EventListener, javax.faces.component.StateHolder, javax.faces.validator.Validator

      @JSFValidator(configExcluded=true)
      public class ByteLengthValidator
      extends Object
      implements javax.faces.component.StateHolder, javax.faces.validator.Validator

  ByteLengthValidator is a `Validator` that checks the value of the corresponding component for its byte length for the set character encoding. The following algorithm is implemented:

  - If the passed value is `null` or empty string, exit immediately.
  - If the current component value is not of String type throw IllegalArgumentException
  - If both `encoding` and `maximum` property has been configured on this `Validator`, check the component value byte length against the maximum. If the component value byte length is greater than this specified maximum, throw a `ValidatorException` containing a MAXIMUM_MESSAGE_ID message.
  - If only `maximum` property has been configured on this `Validator`, check the component value against this limit defaulting the encoding to be `iso-8859-1`. If the component value length is greater than the specified maximum, throw a `ValidatorException` containing a MAXIMUM_MESSAGE_ID message.
  - If a `encoding` property has been configured on this `Validator`, and if it is not a valid Java encoding, then throws a `IllegalCharsetNameException`
  - If `maximumMessageDetail` is set, it is used for constructing faces message, when validation fails. The message can contain placeholders which will be replaced as specified in `MAXIMUM_MESSAGE_ID`
  Version:
    $Name: $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/validator/ByteLengthValidator.java#0 $) $Date: 10-nov-2005.19:08:32 $
  See Also:
    `setMessageDetailMaximum(String)`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `MAXIMUM_MESSAGE_ID` The message identifier of the `FacesMessage` to be created if the maximum byte length check fails.
    `static String` | `VALIDATOR_ID` Standard validator id for this validator.

    - ### Fields inherited from interface javax.faces.validator.Validator

      `NOT_IN_RANGE_MESSAGE_ID`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ByteLengthValidator()` Construct a `Validator` with `iso-8859-1` as the encoding and `zero` as the maximum bytes allowed.
    `ByteLengthValidator(int maximum, String encoding)` Construct a `Validator` with the specified preconfigured values.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(Object object)` Compares this ByteLengthValidator with the specified Object for equality.
    `String` | `getEncoding()` Return the character encoding set for this `Validator` or `iso-8859-1` if it has not been set.
    `String` | `getHintMaximum()` Return custom hint message.
    `protected javax.faces.application.FacesMessage` | `getLengthValidationFailureMessage(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, String value)` The `FacesMessage` to be returned if byte length validation fails.
    `int` | `getMaximum()` Return the maximum bytes to be enforced by this `Validator` or `zero` if it has not been set.
    `String` | `getMessageDetailMaximum()` Return custom detail error message that was set for creating `FacesMessage`, for values that exceeds the maximum byte length.
    `javax.faces.el.ValueBinding` | `getValueBinding(String name)` Deprecated.
    `javax.el.ValueExpression` | `getValueExpression(String name)` Return the `ValueExpression` used to calculate the value for the specified attribute name, if any.
    `int` | `hashCode()` Returns the hash code for this Validator.
    `boolean` | `isDisabled()` Return whether it is disabled.
    `boolean` | `isTransient()`
    `void` | `restoreState(javax.faces.context.FacesContext context, Object state)`
    `Object` | `saveState(javax.faces.context.FacesContext context)`
    `void` | `setDisabled(boolean isDisabled)` Set the value to property `disabled`.
    `void` | `setEncoding(String encoding)` Set the character encoding for this `Validator`.
    `void` | `setHintMaximum(String hintMaximum)` Custom hint message.
    `void` | `setMaximum(int maximum)` Set the maximum bytes to be enforced by this `Validator`.
    `void` | `setMessageDetailMaximum(String maximumMessageDetail)` Custom error message to be used, for creating detail part of the `FacesMessage`, when users input exceeds the maximum byte length.
    `void` | `setTransient(boolean transientValue)`
    `void` | `setValueBinding(String name, javax.faces.el.ValueBinding binding)` Deprecated.
    `void` | `setValueExpression(String name, javax.el.ValueExpression expression)` Set the `ValueExpression` used to calculate the value for the specified attribute if any.
    `void` | `validate(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value)` Validates unless it is too long, in which case throws ValidatorException.

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### MAXIMUM_MESSAGE_ID

          public static final String MAXIMUM_MESSAGE_ID

      The message identifier of the `FacesMessage` to be created if the maximum byte length check fails. The message format string for this message may optionally include `{0}`, `{1}` and `{2}` placeholders, which will be replaced by input value, label associated with the component and the maximum bytes respectively.

      See Also:
        Constant Field Values

    - #### VALIDATOR_ID

          public static final String VALIDATOR_ID

      Standard validator id for this validator.

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ByteLengthValidator

          public ByteLengthValidator()

      Construct a `Validator` with `iso-8859-1` as the encoding and `zero` as the maximum bytes allowed.

    - #### ByteLengthValidator

          public ByteLengthValidator(int maximum,
                             String encoding)

      Construct a `Validator` with the specified preconfigured values.

      Parameters:
        `maximum` - the maximum number of bytes allowed.
        `encoding` - the Java character set encoding. This must be an encoding supported by Java.

  - ### Method Detail

    - #### setEncoding

          public void setEncoding(String encoding)

      Set the character encoding for this `Validator`.

      Parameters:
        `encoding` - The character encoding.

    - #### getEncoding

          @JSFProperty(defaultValue="iso-8859-1")
          public String getEncoding()

      Return the character encoding set for this `Validator` or `iso-8859-1` if it has not been set.

    - #### setMaximum

          public void setMaximum(int maximum)

      Set the maximum bytes to be enforced by this `Validator`.

      Parameters:
        `maximum` - The new maximum value

    - #### getMaximum

          @JSFProperty
          public int getMaximum()

      Return the maximum bytes to be enforced by this `Validator` or `zero` if it has not been set.

    - #### setMessageDetailMaximum

          public void setMessageDetailMaximum(String maximumMessageDetail)

      Custom error message to be used, for creating detail part of the `FacesMessage`, when users input exceeds the maximum byte length.

      Overrides detail message identified by message id `MAXIMUM_MESSAGE_ID`
      Parameters:
        `maximumMessageDetail` - Custom error message.

    - #### getMessageDetailMaximum

          @JSFProperty
          public String getMessageDetailMaximum()

      Return custom detail error message that was set for creating `FacesMessage`, for values that exceeds the maximum byte length.

      Returns:
        Custom error message.
      See Also:
        `setMessageDetailMaximum(String)`

    - #### setHintMaximum

          public void setHintMaximum(String hintMaximum)

      Custom hint message.

      Overrides default hint message
      Parameters:
        `hintMaximum` - Custom hint message.

    - #### getHintMaximum

          @JSFProperty(tagExcluded=true)
          public String getHintMaximum()

      Return custom hint message.

      Returns:
        Custom hint message.
      See Also:
        `setHintMaximum(String)`

    - #### validate

          public void validate(javax.faces.context.FacesContext context,
                      javax.faces.component.UIComponent component,
                      Object value)
                        throws javax.faces.validator.ValidatorException

      Validates unless it is too long, in which case throws ValidatorException.

      Specified by:
        `validate` in interface `javax.faces.validator.Validator`
      Throws:
        `javax.faces.validator.ValidatorException` - if validation fails
        `NullPointerException` - if `context`
        `IllegalCharsetNameException` - if `encoding` is
        `IllegalArgumentException` - if `value` is not of type `String` `unsupported` or `component` is `null`

    - #### saveState

          public Object saveState(javax.faces.context.FacesContext context)

      Specified by:
        `saveState` in interface `javax.faces.component.StateHolder`

    - #### restoreState

          public void restoreState(javax.faces.context.FacesContext context,
                          Object state)

      Specified by:
        `restoreState` in interface `javax.faces.component.StateHolder`

    - #### isTransient

          @JSFProperty(istransient=true,
                       tagExcluded=true)
          public boolean isTransient()

      Specified by:
        `isTransient` in interface `javax.faces.component.StateHolder`

    - #### setTransient

          public void setTransient(boolean transientValue)

      Specified by:
        `setTransient` in interface `javax.faces.component.StateHolder`

    - #### setValueExpression

          public void setValueExpression(String name,
                                javax.el.ValueExpression expression)

      Set the `ValueExpression` used to calculate the value for the specified attribute if any.

      Parameters:
        `name` - Name of the attribute for which to set a `ValueExpression`
        `expression` - The `ValueExpression` to set, or `null` to remove any currently set `ValueExpression`
      Throws:
        `NullPointerException` - if `name` is `null`
        `IllegalArgumentException` - if `name` is not a valid attribute of this converter

    - #### getValueExpression

          public javax.el.ValueExpression getValueExpression(String name)

      Return the `ValueExpression` used to calculate the value for the specified attribute name, if any.

      Parameters:
        `name` - Name of the attribute or property for which to retrieve a `ValueExpression`
      Throws:
        `NullPointerException` - if `name` is `null`
        `IllegalArgumentException` - if `name` is not a valid attribute of this converter

    - #### setValueBinding

          public void setValueBinding(String name,
                             javax.faces.el.ValueBinding binding)

      Deprecated.

      Set the `ValueBinding` used to calculate the value for the specified attribute if any.

      Parameters:
        `name` - Name of the attribute for which to set a `ValueBinding`
        `binding` - The `ValueBinding` to set, or `null` to remove any currently set `ValueBinding`
      Throws:
        `NullPointerException` - if `name` is `null`
        `IllegalArgumentException` - if `name` is not a valid attribute of this validator

    - #### getValueBinding

          public javax.faces.el.ValueBinding getValueBinding(String name)

      Deprecated.

      Return the `ValueBinding` used to calculate the value for the specified attribute name, if any.

      Parameters:
        `name` - Name of the attribute or property for which to retrieve a `ValueBinding`
      Throws:
        `NullPointerException` - if `name` is `null`
        `IllegalArgumentException` - if `name` is not a valid attribute of this validator

    - #### equals

          public boolean equals(Object object)

      Compares this ByteLengthValidator with the specified Object for equality.

      Overrides:
        `equals` in class `Object`
      Parameters:
        `object` - Object to which this ByteLengthValidator is to be compared.
      Returns:
        true if and only if the specified Object is a ByteLengthValidator and if the values encoding, maximum and transient are equal.

    - #### hashCode

          public int hashCode()

      Returns the hash code for this Validator.

      Overrides:
        `hashCode` in class `Object`
      Returns:
        a hash code value for this object.

    - #### setDisabled

          public void setDisabled(boolean isDisabled)

      Set the value to property `disabled`. Default value is false.

      Parameters:
        `isDisabled` - `true` if it's disabled, `false` otherwise.

    - #### isDisabled

          public boolean isDisabled()

      Return whether it is disabled.
      Returns:
        true if it's disabled and false if it's enabled.

    - #### getLengthValidationFailureMessage

          protected javax.faces.application.FacesMessage getLengthValidationFailureMessage(javax.faces.context.FacesContext context,
                                                                               javax.faces.component.UIComponent component,
                                                                               String value)

      The `FacesMessage` to be returned if byte length validation fails.
      Parameters:
        `context` - Faces context
        `value` - The value entered / set by the user on the component
      Returns:
        error message when the length exceeds the maximum byte length set.

Copyright © 2001-2017 The Apache Software Foundation. All Rights Reserved.