org.apache.click.control
Class HiddenField

java.lang.Object
  extended by org.apache.click.control.AbstractControl
      extended by org.apache.click.control.Field
          extended by org.apache.click.control.HiddenField
All Implemented Interfaces:
Serializable, Control, Stateful

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:

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 Summary
protected  Class<?> valueClass
          The field value Class.
protected  Object valueObject
          The field value Object.
 
Fields inherited from class org.apache.click.control.Field
disabled, error, focus, form, help, label, labelStyle, labelStyleClass, parentStyleClassHint, parentStyleHint, readonly, required, tabindex, title, trim, validate, value
 
Fields inherited from class org.apache.click.control.AbstractControl
actionListener, attributes, behaviors, headElements, listener, listenerMethod, messages, name, parent, styles
 
Fields inherited from interface org.apache.click.Control
CONTROL_MESSAGES
 
Constructor Summary
HiddenField()
          Create an HiddenField with no name or Class defined.
HiddenField(String name, Class<?> valueClass)
          Construct a HiddenField with the given name and Class.
HiddenField(String name, Object value)
          Construct a HiddenField with the given name and value object.
 
Method Summary
 void bindRequestValue()
          This method binds the submitted request value to the Field's value.
 String getTag()
          Return the hiddenfield's html tag: input.
 String getType()
          Return the input type: 'hidden'.
 String getValidationJavaScript()
          Returns null to ensure no client side JavaScript validation is performed.
 String getValue()
          Return the Field value.
 Class<?> getValueClass()
          Return the registered Class for the Hidden Field value Object.
 Object getValueObject()
          Return the value Object of the hidden field.
 boolean isHidden()
          Returns true.
 void render(HtmlStringBuffer buffer)
          Render the HTML representation of the HiddenField.
 void setValue(String value)
          Set the Field value.
 void setValueClass(Class<?> valueClass)
          Set the registered Class for the Hidden Field value Object.
 void setValueObject(Object value)
          Set the value of the field using the given object.
 
Methods inherited from class org.apache.click.control.Field
getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getLabelStyle, getLabelStyleClass, getParentStyleClassHint, getParentStyleHint, getRequestValue, getState, getTabIndex, getTextAlign, getTitle, getValidate, getWidth, isDisabled, isReadonly, isRequired, isTrim, isValid, onProcess, removeState, renderTagBegin, restoreState, saveState, setDisabled, setError, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setLabelStyle, setLabelStyleClass, setListener, setParent, setParentStyleClassHint, setParentStyleHint, setReadonly, setRequired, setState, setTabIndex, setTextAlign, setTitle, setTrim, setValidate, setWidth, validate
 
Methods inherited from class org.apache.click.control.AbstractControl
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getControlSizeEst, getHeadElements, getHtmlImports, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasBehaviors, hasStyles, isAjaxTarget, onDeploy, onDestroy, onInit, onRender, removeBehavior, removeStyleClass, renderTagEnd, setActionListener, setAttribute, setId, setName, setStyle, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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

getTag

public String getTag()
Return the hiddenfield's html tag: input.

Overrides:
getTag in class AbstractControl
Returns:
this controls html tag
See Also:
AbstractControl.getTag()

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()

setValueObject

public void setValueObject(Object value)
Description copied from class: Field
Set the value of the field using the given object.

Overrides:
setValueObject in class Field
Parameters:
value - the object value to set
See Also:
Field.setValueObject(Object)

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 Control
Overrides:
render in class AbstractControl
Parameters:
buffer - the specified buffer to render the control's output to
See Also:
Control.render(org.apache.click.util.HtmlStringBuffer)