org.apache.click.extras.control
Class AbstractContainerField

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

public abstract class AbstractContainerField
extends Field
implements Container

Provides an abstract convenience class that implements Container and extend Field.

This control is only rarely used or necessary. The primary use case is for creating custom Containers that will be treated as Field instances by the Form.

Here is an example of a FieldBorder which wraps Fields in a <div> element. The FieldBorder container can be passed to the Form and will be treated as a normal Field.

 public class FieldBorder extends AbstractContainerField {
     public FieldBorder(String name) {
         super(name);
     }

     public String getTag() {
         return "div";
     }

     public Control add(Field field) {
         return getContainer().add(field);
     }
 } 
If you need to bind a request parameter to this field value, please see bindRequestValue().

See Also:
Serialized Form

Field Summary
protected  Map<String,Control> controlMap
          The map of controls keyed by field name.
protected  List<Control> controls
          The list of controls.
 
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
AbstractContainerField()
          Create an AbstractContainerField with no name defined.
AbstractContainerField(String name)
          Create an AbstractContainerField with the given name.
AbstractContainerField(String name, String label)
          Construct an AbstractContainerField with the given name and label.
 
Method Summary
 Control add(Control control)
           
 void bindRequestValue()
          This method does nothing by default.
 boolean contains(Control control)
           
 Container getContainer()
          Deprecated. the internal container instance was removed, AbstractContainerField can be used without accessing the internal container
 Control getControl(String controlName)
           
protected  Map<String,Control> getControlMap()
          Return the map of controls where each map's key / value pair will consist of the control name and instance.
 List<Control> getControls()
           
protected  int getControlSizeEst()
           
 boolean hasControls()
          Returns true if this container has existing controls, false otherwise.
 Control insert(Control control, int index)
          Add the control to the container at the specified index, and return the added instance.
 void onDestroy()
           
 void onInit()
           
 boolean onProcess()
           
 void onRender()
           
 boolean remove(Control control)
           
 void render(HtmlStringBuffer buffer)
          By default render the container and all its child controls to the specified buffer.
protected  void renderChildren(HtmlStringBuffer buffer)
          Render this container children to the specified buffer.
protected  void renderContent(HtmlStringBuffer buffer)
          Render this container content to the specified buffer.
protected  void renderTagBegin(String tagName, HtmlStringBuffer buffer)
          Render the Container tag and common attributes including id, class and style.
protected  void renderTagEnd(String tagName, HtmlStringBuffer buffer)
           
 Control replace(Control currentControl, Control newControl)
          Deprecated. this method was used for stateful pages, which have been deprecated
 void setParent(Object parent)
          Set the parent of the Field.
 String toString()
          Returns the HTML representation of this control.
 
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, getValidationJavaScript, getValue, getValueObject, getWidth, isDisabled, isHidden, isReadonly, isRequired, isTrim, isValid, removeState, restoreState, saveState, setDisabled, setError, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setLabelStyle, setLabelStyleClass, setListener, setParentStyleClassHint, setParentStyleHint, setReadonly, setRequired, setState, setTabIndex, setTextAlign, setTitle, setTrim, setValidate, setValue, setValueObject, setWidth, validate
 
Methods inherited from class org.apache.click.control.AbstractControl
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getHeadElements, getHtmlImports, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, getTag, hasAttribute, hasAttributes, hasBehaviors, hasStyles, isAjaxTarget, onDeploy, removeBehavior, removeStyleClass, setActionListener, setAttribute, setId, setName, setStyle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.click.Control
getBehaviors, getContext, getHeadElements, getId, getMessages, getName, getParent, hasBehaviors, isAjaxTarget, onDeploy, setListener, setName
 

Field Detail

controls

protected List<Control> controls
The list of controls.


controlMap

protected Map<String,Control> controlMap
The map of controls keyed by field name.

Constructor Detail

AbstractContainerField

public AbstractContainerField()
Create an AbstractContainerField with no name defined.


AbstractContainerField

public AbstractContainerField(String name)
Create an AbstractContainerField with the given name.

Parameters:
name - the ContainerField name

AbstractContainerField

public AbstractContainerField(String name,
                              String label)
Construct an AbstractContainerField with the given name and label.

Parameters:
name - the name of the Field
label - the label of the Field
Method Detail

add

public Control add(Control control)
Specified by:
add in interface Container
Parameters:
control - the control to add to the container and return
Returns:
the control that was added to the container
Throws:
IllegalArgumentException - if the control is null
See Also:
Please note: if the container contains a control with the same name as the given control, that control will be {@link #replace(org.apache.click.Control, org.apache.click.Control) replaced} by the given control. If a control has no name defined it cannot be replaced.

insert

public Control insert(Control control,
                      int index)
Add the control to the container at the specified index, and return the added instance.

Please note: if the container contains a control with the same name as the given control, that control will be replaced by the given control. If a control has no name defined it cannot be replaced.

Specified by:
insert in interface Container
Parameters:
control - the control to add to the container and return
index - the index at which the control is to be inserted
Returns:
the control that was added to the container
Throws:
IllegalArgumentException - if the control is null or if the control and container is the same instance
See Also:
Container.insert(org.apache.click.Control, int).

remove

public boolean remove(Control control)
Specified by:
remove in interface Container
Parameters:
control - the control to remove from the container
Returns:
true if the control was removed from the container
See Also:
Container.remove(org.apache.click.Control)

replace

public Control replace(Control currentControl,
                       Control newControl)
Deprecated. this method was used for stateful pages, which have been deprecated

Replace the control in the container at the specified index, and return the newly added control.

Specified by:
replace in interface Container
Parameters:
currentControl - the control currently contained in the container
newControl - the control to replace the current control contained in the container
Returns:
the new control that replaced the current control
Throws:
IllegalArgumentException - if the currentControl or newControl is null
IllegalStateException - if the currentControl is not contained in the container
See Also:
Container.replace(org.apache.click.Control, org.apache.click.Control)

getContainer

public Container getContainer()
Deprecated. the internal container instance was removed, AbstractContainerField can be used without accessing the internal container

Return the internal container instance.

Returns:
the internal container instance

getControls

public List<Control> getControls()
Specified by:
getControls in interface Container
Returns:
the sequential list of controls held by the container
See Also:
Container.getControls()

getControl

public Control getControl(String controlName)
Specified by:
getControl in interface Container
Parameters:
controlName - the name of the control to get from the container
Returns:
the named control from the container if found or null otherwise
See Also:
Container.getControl(java.lang.String)

contains

public boolean contains(Control control)
Specified by:
contains in interface Container
Parameters:
control - the control whose presence in this container is to be tested
Returns:
true if the container contains the specified control
See Also:
Container.contains(org.apache.click.Control)

hasControls

public boolean hasControls()
Returns true if this container has existing controls, false otherwise.

Specified by:
hasControls in interface Container
Returns:
true if the container has existing controls, false otherwise.
See Also:
AbstractContainer.hasControls()

setParent

public void setParent(Object parent)
Set the parent of the Field.

Specified by:
setParent in interface Control
Overrides:
setParent in class Field
Parameters:
parent - the parent of the Control
Throws:
IllegalArgumentException - if the given parent instance is referencing this object: if (parent == this)
See Also:
Control.setParent(Object)

bindRequestValue

public void bindRequestValue()
This method does nothing by default.

Subclasses can override this method to binds the submitted request value to the Field value. For example:

 public CoolField extends AbstractContainerField {

     public CoolField(String name) {
         super(name);
     }

     public void bindRequestValue() {
         setValue(getRequestValue());
     }
 } 

Overrides:
bindRequestValue in class Field
See Also:
Field.getRequestValue()

onProcess

public boolean onProcess()
Specified by:
onProcess in interface Control
Overrides:
onProcess in class Field
Returns:
true to continue Page event processing or false otherwise
See Also:
Control.onProcess()

onDestroy

public void onDestroy()
Specified by:
onDestroy in interface Control
Overrides:
onDestroy in class AbstractControl
See Also:
Control.onDestroy()

onInit

public void onInit()
Specified by:
onInit in interface Control
Overrides:
onInit in class AbstractControl
See Also:
Control.onInit()

onRender

public void onRender()
Specified by:
onRender in interface Control
Overrides:
onRender in class AbstractControl
See Also:
Control.onRender()

render

public void render(HtmlStringBuffer buffer)
By default render the container and all its child controls to the specified buffer.

If AbstractControl.getTag() returns null, this method will render only its child controls.

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:
AbstractControl.render(org.apache.click.util.HtmlStringBuffer)

toString

public String toString()
Returns the HTML representation of this control.

This method delegates the rendering to the method render(org.apache.click.util.HtmlStringBuffer). The size of buffer is determined by getControlSizeEst().

Overrides:
toString in class AbstractControl
Returns:
the HTML representation of this control

renderTagBegin

protected void renderTagBegin(String tagName,
                              HtmlStringBuffer buffer)
Render the Container tag and common attributes including id, class and style. The name attribute is not rendered by this container.

Overrides:
renderTagBegin in class Field
Parameters:
tagName - the name of the tag to render
buffer - the buffer to append the output to
See Also:
AbstractControl.renderTagBegin(java.lang.String, org.apache.click.util.HtmlStringBuffer)

renderTagEnd

protected void renderTagEnd(String tagName,
                            HtmlStringBuffer buffer)
Overrides:
renderTagEnd in class AbstractControl
Parameters:
tagName - the name of the tag to close
buffer - the buffer to append the output to
See Also:
AbstractControl.renderTagEnd(java.lang.String, org.apache.click.util.HtmlStringBuffer)

renderContent

protected void renderContent(HtmlStringBuffer buffer)
Render this container content to the specified buffer.

Parameters:
buffer - the buffer to append the output to
See Also:
AbstractContainer.renderContent(org.apache.click.util.HtmlStringBuffer)

renderChildren

protected void renderChildren(HtmlStringBuffer buffer)
Render this container children to the specified buffer.

Parameters:
buffer - the buffer to append the output to
See Also:
AbstractContainer.renderChildren(org.apache.click.util.HtmlStringBuffer)

getControlMap

protected Map<String,Control> getControlMap()
Return the map of controls where each map's key / value pair will consist of the control name and instance.

Returns:
the map of controls
See Also:
AbstractContainer.getControlMap()

getControlSizeEst

protected int getControlSizeEst()
Overrides:
getControlSizeEst in class AbstractControl
Returns:
the estimated rendered control size in characters
See Also:
AbstractControl.getControlSizeEst()