net.sf.click.extras.control
Class AbstractContainerField

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

public abstract class AbstractContainerField
extends Field
implements Container

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

AbstractContainerField delegates Contain specific actions to an internal Container instance. You can access the Container instance through getContainer().

If you need to bind a request parameter to this fields value, please see bindRequestValue().

Here is an example of a Border Control that can wrap a Button and render a div border around it.

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

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

     public Control addControl(Button button) {
         return getContainer().addControl(button);
     }
 } 

Author:
Bob Schellink
See Also:
Serialized Form

Field Summary
protected  AbstractContainer container
          Internal container instance.
 
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
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()
          Return the internal container instance.
 Control getControl(String controlName)
           
protected  Map getControlMap()
          Return the map of controls where each map's key / value pair will consist of the control name and instance.
 List getControls()
           
protected  int getControlSizeEst()
           
 String getHtmlImports()
          Return the HTML head import statements for contained controls.
 boolean hasControls()
          Returns true if this container has existing controls, false otherwise.
 Control insert(Control control, int index)
           
 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 renderTagEnd(String tagName, HtmlStringBuffer buffer)
           
 void setParent(Object parent)
          Set the parent of the Field.
 String toString()
          Returns the HTML representation of this control.
 
Methods inherited from class net.sf.click.control.Field
getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getRequestValue, getTabIndex, getTextAlign, getTitle, getValidate, getValidationJavaScript, getValue, getValueObject, getWidth, isDisabled, isHidden, isReadonly, isRequired, isValid, setDisabled, setError, setErrorMessage, setErrorMessage, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setListener, setReadonly, setRequired, setTabIndex, setTextAlign, setTitle, setValidate, setValue, setValueObject, setWidth, validate
 
Methods inherited from class net.sf.click.control.AbstractControl
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, getTag, hasAttribute, hasAttributes, hasStyles, onDeploy, registerActionEvent, removeStyleClass, renderTagBegin, 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 net.sf.click.Control
getContext, getId, getMessages, getName, getParent, onDeploy, setListener, setName
 

Field Detail

container

protected AbstractContainer container
Internal container instance.

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
See Also:
Container.add(net.sf.click.Control).

insert

public Control insert(Control control,
                      int index)
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
See Also:
Container.insert(net.sf.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(net.sf.click.Control)

getContainer

public Container getContainer()
Return the internal container instance.

Returns:
the internal container instance

getControls

public List 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(net.sf.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
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)

getHtmlImports

public String getHtmlImports()
Return the HTML head import statements for contained controls.

Specified by:
getHtmlImports in interface Control
Returns:
the HTML includes statements for the contained control stylesheet and JavaScript files
See Also:
Control.getHtmlImports()

bindRequestValue

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

Subclasses should override this method to binds the submitted request value to the Field's value. For example:

 public CoolField extends AbstractContainerField {

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

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

     // Below is the actual getRequestValue implementation as defined
     // in Field. This is done solely to show how to retrieve the
     // request parameter based on the fields name.
     protected String getRequestValue() {
         String value = getContext().getRequestParameter(getName());
         if (value != null) {
             return value.trim();
         } else {
             return "";
         }
     }
 }
 
Note you can use method Field.getRequestValue() to retrieve the fields value if the request parameter is the fields name.


onProcess

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

onDestroy

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

onInit

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

onRender

public void onRender()
Specified by:
onRender in interface Control
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
Parameters:
buffer - the specified buffer to render the control's output to
See Also:
AbstractControl.render(net.sf.click.util.HtmlStringBuffer)

toString

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

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

Returns:
the HTML representation of this control

renderTagEnd

protected void renderTagEnd(String tagName,
                            HtmlStringBuffer buffer)
Parameters:
tagName - the name of the tag to close
buffer - the buffer to append the output to
See Also:
AbstractControl.renderTagEnd(java.lang.String, net.sf.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(net.sf.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(net.sf.click.util.HtmlStringBuffer)

getControlMap

protected Map 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()
Returns:
the estimated rendered control size in characters
See Also:
AbstractControl.getControlSizeEst()