net.sf.click.control
Class HiddenField

java.lang.Object
  extended bynet.sf.click.control.AbstractControl
      extended bynet.sf.click.control.Field
          extended bynet.sf.click.control.HiddenField
All Implemented Interfaces:
Control, Serializable

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

Author:
Malcolm Edgar
See Also:
Serialized Form

Field Summary
protected  Class valueClass
          The field value Class.
protected  Object valueObject
          The field value Object.
 
Fields inherited from class net.sf.click.control.Field
disabled, error, focus, form, help, label, readonly, required, tabindex, title, validate, value
 
Fields inherited from class net.sf.click.control.AbstractControl
actionListener, attributes, listener, listenerMethod, messages, name, parent, styles
 
Fields inherited from interface net.sf.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 net.sf.click.control.Field
getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getRequestValue, getTabIndex, getTextAlign, getTitle, getValidate, getWidth, isDisabled, isReadonly, isRequired, isValid, onInit, onProcess, setDisabled, setError, setErrorMessage, setErrorMessage, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setListener, setParent, setReadonly, setRequired, setTabIndex, setTextAlign, setTitle, setValidate, setWidth, validate
 
Methods inherited from class net.sf.click.control.AbstractControl
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getControlSizeEst, getHtmlImports, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasStyles, onDeploy, onDestroy, onRender, registerActionEvent, removeStyleClass, renderTagBegin, 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(net.sf.click.util.HtmlStringBuffer)