Class HiddenField

  • All Implemented Interfaces:
    Serializable, org.apache.click.Stateful, org.openidentityplatform.openam.click.Control

    public class HiddenField
    extends Field
    Provides a Hidden Field control:   <input type='hidden'>.

    The HiddenField control is useful for storing state information in a Form, such as object ids, instead of using the Session object. This control is capable of supporting the following classes:

    • Boolean
    • Date
    • Double
    • Float
    • Integer
    • Long
    • Short
    • String
    • Serializable

    Serializable non-primitive objects will be serialized, compressed and Base64 encoded, using ClickUtils.encode(Object) method, and decoded using the corresponding ClickUtils.decode(String) method.

    HiddenField Example

    An example is provided below which uses a hidden field to count the number of times a form is consecutively submitted. The count is displayed in the page template using the model "count" value.
     public class CountPage extends Page {
    
         public Form form = new Form();
         public Integer count;
    
         private HiddenField counterField = new HiddenField("counterField", Integer.class);
    
         public CountPage() {
             form.add(counterField);
             form.add(new Submit("ok", "  OK  "));
         }
    
         public void onGet() {
             count = new Integer(0);
             counterField.setValueObject(count);
         }
    
         public void onPost() {
             count = (Integer) counterField.getValueObject();
             count = new Integer(count.intValue() + 1);
             counterField.setValueObject(count);
         }
     } 
    See also W3C HTML reference INPUT
    See Also:
    Serialized Form
    • Field Detail

      • valueObject

        protected Object valueObject
        The field value Object.
      • valueClass

        protected Class<?> valueClass
        The field value Class.
    • Constructor Detail

      • HiddenField

        public HiddenField​(String name,
                           Class<?> valueClass)
        Construct a HiddenField with the given name and Class.
        Parameters:
        name - the name of the hidden field
        valueClass - the Class of the value Object
      • HiddenField

        public HiddenField​(String name,
                           Object value)
        Construct a HiddenField with the given name and value object.
        Parameters:
        name - the name of the hidden field
        value - the value object
      • HiddenField

        public HiddenField()
        Create an HiddenField with no name or Class defined. Please note the HiddenField's name and value Class must be defined before it is valid.
    • Method Detail

      • isHidden

        public boolean isHidden()
        Returns true.
        Overrides:
        isHidden in class Field
        Returns:
        true
        See Also:
        Field.isHidden()
      • getType

        public String getType()
        Return the input type: 'hidden'.
        Returns:
        the input type: 'hidden'
      • getValue

        public String getValue()
        Description copied from class: Field
        Return the Field value.
        Overrides:
        getValue in class Field
        Returns:
        the Field value
        See Also:
        Field.getValue()
      • setValue

        public void setValue​(String value)
        Description copied from class: Field
        Set the Field value.
        Overrides:
        setValue in class Field
        Parameters:
        value - the Field value
        See Also:
        Field.setValue(String)
      • getValueClass

        public Class<?> getValueClass()
        Return the registered Class for the Hidden Field value Object.
        Returns:
        the registered Class for the Hidden Field value Object
      • setValueClass

        public void setValueClass​(Class<?> valueClass)
        Set the registered Class for the Hidden Field value Object.
        Parameters:
        valueClass - the registered Class for the Hidden Field value Object
      • getValueObject

        public Object getValueObject()
        Return the value Object of the hidden field.
        Overrides:
        getValueObject in class Field
        Returns:
        the object representation of the Field value
        See Also:
        Field.getValueObject()
      • getValidationJavaScript

        public String getValidationJavaScript()
        Returns null to ensure no client side JavaScript validation is performed.
        Overrides:
        getValidationJavaScript in class Field
        Returns:
        null to ensure no client side JavaScript validation is performed
      • bindRequestValue

        public void bindRequestValue()
        This method binds the submitted request value to the Field's value.
        Overrides:
        bindRequestValue in class Field
      • render

        public void render​(HtmlStringBuffer buffer)
        Render the HTML representation of the HiddenField.
        Specified by:
        render in interface org.openidentityplatform.openam.click.Control
        Overrides:
        render in class AbstractControl
        Parameters:
        buffer - the specified buffer to render the control's output to
        See Also:
        Control.render(HtmlStringBuffer)