org.apache.click.extras.control
Class TabbedForm

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

public class TabbedForm
extends Form

Provides a Tabbed Form control:   <form method='post'>.

This class provides a JavaScript enabled tab sheet for control. This control is particularly useful for large forms as fields can be grouped into fieldsets and displayed in individual tab sheets.

The rendered field error messages are tab sheet aware so that clicking on a error message link will open the appropriate tab sheet.

TabbedForm Example

A form delivery details editor example, with separate "Contact Details", "Delivery Details" and "Payment Details" tab sheets, is provided below. Note how tabsheets are created with FieldSet control which are added to the form.
 public DeliveryDetailsEditor() {

     form.setBackgroundColor("#F7FFAF");
     form.setTabHeight("210px");
     form.setTabWidth("420px");

     // Contact tab sheet

     FieldSet contactTabSheet = new FieldSet("contactDetails");
     form.addTabSheet(contactTabSheet);

     contactTabSheet.add(new TitleSelect("title"));
     contactTabSheet.add(new TextField("firstName"));
     contactTabSheet.add(new TextField("middleNames"));
     contactTabSheet.add(new TextField("surname", true));
     contactTabSheet.add(contactNumber);
     contactTabSheet.add(new EmailField("email"));

     // Delivery tab sheet

     FieldSet deliveryTabSheet = new FieldSet("deliveryDetails");
     form.addTabSheet(deliveryTabSheet);

     TextArea textArea = new TextArea("deliveryAddress", true);
     textArea.setCols(30);
     textArea.setRows(3);
     deliveryTabSheet.add(textArea);

     deliveryTabSheet.add(new DateField("deliveryDate"));

     PackagingRadioGroup packaging = new PackagingRadioGroup("packaging");
     packaging.setValue("STD");
     deliveryTabSheet.add(packaging);

     deliveryTabSheet.add(telephoneOnDelivery);

     // Payment tab sheet

     FieldSet paymentTabSheet = new FieldSet("paymentDetails");
     form.addTabSheet(paymentTabSheet);

     paymentGroup.add(new Radio("cod", "Cash On Delivery"));
     paymentGroup.add(new Radio("credit", "Credit Card"));
     paymentGroup.setVerticalLayout(false);
     paymentTabSheet.add(paymentGroup);

     paymentTabSheet.add(cardName);
     paymentTabSheet.add(cardNumber);
     paymentTabSheet.add(expiry);
     expiry.setSize(4);
     expiry.setMaxLength(4);

     // Buttons

     form.add(new Submit("ok", "   OK   ",  this, "onOkClick"));
     form.add(new Submit("cancel", this, "onCancelClick"));

     addControl(form);
 } 

CSS and JavaScript resources

In addition to Form's resources, the TabbedForm control makes use of the following resources (which Click automatically deploys to the application directory, /click): To import these TabbedForm files simply reference the variables $headElements and $jsElements in the page template.

See Also:
Serialized Form

Field Summary
protected  String backgroundColor
          The form HTML background color.
protected  int displayTab
          The tab number to display (indexed from 1).
protected  String tabHeight
          The tab sheet height HTML attribute value.
protected  List<FieldSet> tabSheets
          The list of FieldSet tab sheets.
protected  String tabWidth
          The tab sheet width HTML attribute value.
protected  String template
          The path of the tabbed form Velocity template to render.
 
Fields inherited from class org.apache.click.control.Form
actionURL, ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, buttonAlign, buttonList, buttonStyle, columns, defaultFieldSize, disabled, enctype, error, errorsAlign, errorsPosition, errorsStyle, fieldList, fieldStyle, fieldWidths, FOCUS_JAVASCRIPT, FORM_NAME, formSubmission, javaScriptValidation, labelAlign, labelsPosition, labelStyle, method, MULTIPART_FORM_DATA, POSITION_BOTTOM, POSITION_LEFT, POSITION_MIDDLE, POSITION_TOP, readonly, SUBMIT_CHECK, validate
 
Fields inherited from class org.apache.click.control.AbstractContainer
controlMap, controls
 
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
TabbedForm()
          Create a new tabbed form instance with no name defined.
TabbedForm(String name)
          Create a new tabbed form instance with the given name.
 
Method Summary
 void addTabSheet(FieldSet tabSheet)
          Add the given FieldSet tab sheet to the form.
 String getBackgroundColor()
          Return the form HTML background color.
 int getDisplayTab()
          Return the number of the tab sheet to display (indexed from 1).
 List<Element> getHeadElements()
          Return the TabbedForm HTML HEAD elements for the following resources: click/extras-control.js click/extras-control.css Additionally all the Form import statements are also returned.
 String getTabHeight()
          Return the tab sheet height HTML attribute value.
 int getTabSheetNumber(String fieldName)
          Return the tab sheet number for the given field name, indexed from 1.
 List<FieldSet> getTabSheets()
          Return list FieldSet tab sheets.
 String getTabWidth()
          Return the tab sheet width HTML attribute value.
 String getTemplate()
          Return the path of the Velocity template to render.
 boolean onProcess()
          Process the Form request.
 void render(HtmlStringBuffer buffer)
          Render the HTML representation of the TabbedForm.
protected  void renderValidationJavaScript(HtmlStringBuffer buffer, List<Field> formFields)
           
 void setBackgroundColor(String value)
          Set the form HTML background color.
 void setDisplayTab(int value)
          Set the number of the tab sheet to display (indexed from 1).
 void setTabHeight(String value)
          Set the tab sheet height HTML attribute value.
 void setTabWidth(String value)
          Set the tab sheet width HTML attribute value.
 void setTemplate(String template)
          Set the path of the Velocity template to render.
 String toString()
          Return the HTML string representation of the form.
 
Methods inherited from class org.apache.click.control.Form
add, add, add, add, clearErrors, clearValues, copyFrom, copyFrom, copyTo, copyTo, endTag, getActionURL, getButtonAlign, getButtonList, getButtonStyle, getColumns, getControlSizeEst, getDefaultFieldSize, getEnctype, getError, getErrorFields, getErrorsAlign, getErrorsPosition, getErrorsStyle, getField, getFieldList, getFields, getFieldStyle, getFieldValue, getFieldWidths, getFormSizeEst, getJavaScriptValidation, getLabelAlign, getLabelsPosition, getLabelStyle, getMethod, getState, getTag, getValidate, hasPostError, insert, isDisabled, isFormSubmission, isJavaScriptValidation, isReadonly, isValid, onDestroy, onSubmitCheck, onSubmitCheck, onSubmitCheck, performSubmitCheck, remove, removeField, removeFields, removeState, renderButtons, renderControls, renderErrors, renderFields, renderFocusJavaScript, renderHeader, renderTagEnd, replace, restoreState, saveState, setActionURL, setButtonAlign, setButtonStyle, setColumns, setDefaultFieldSize, setDisabled, setEnctype, setError, setErrorsAlign, setErrorsPosition, setErrorsStyle, setFieldStyle, setJavaScriptValidation, setLabelAlign, setLabelsPosition, setLabelStyle, setListener, setMethod, setName, setReadonly, setState, setValidate, startTag, validate, validateFileUpload
 
Methods inherited from class org.apache.click.control.AbstractContainer
contains, getControl, getControlMap, getControls, hasControls, onInit, onRender, renderChildren, renderContent, renderTagEnd
 
Methods inherited from class org.apache.click.control.AbstractControl
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getHtmlImports, getId, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasBehaviors, hasStyles, isAjaxTarget, onDeploy, removeBehavior, removeStyleClass, renderTagBegin, setActionListener, setAttribute, setId, setParent, 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, getId, getMessages, getName, getParent, hasBehaviors, isAjaxTarget, onDeploy, setParent
 

Field Detail

backgroundColor

protected String backgroundColor
The form HTML background color. The default background color is "#EFEFEF".


displayTab

protected int displayTab
The tab number to display (indexed from 1). The default tab number is 1.


tabHeight

protected String tabHeight
The tab sheet height HTML attribute value.


tabSheets

protected List<FieldSet> tabSheets
The list of FieldSet tab sheets.


tabWidth

protected String tabWidth
The tab sheet width HTML attribute value.


template

protected String template
The path of the tabbed form Velocity template to render. The default template path is "/org/apache/click/extras/control/TabbedForm.htm".

Constructor Detail

TabbedForm

public TabbedForm(String name)
Create a new tabbed form instance with the given name.

Parameters:
name - the name of the form

TabbedForm

public TabbedForm()
Create a new tabbed form instance with no name defined.

Please note the control's name must be defined before it is valid.

Method Detail

addTabSheet

public void addTabSheet(FieldSet tabSheet)
Add the given FieldSet tab sheet to the form.

Parameters:
tabSheet - the FieldSet tab sheet to add

getBackgroundColor

public String getBackgroundColor()
Return the form HTML background color.

Returns:
the form HTML background color

setBackgroundColor

public void setBackgroundColor(String value)
Set the form HTML background color.

Parameters:
value - the form HTML background color

getDisplayTab

public int getDisplayTab()
Return the number of the tab sheet to display (indexed from 1).

Returns:
the number of the tab sheet to display

setDisplayTab

public void setDisplayTab(int value)
Set the number of the tab sheet to display (indexed from 1).

Parameters:
value - the number of the tab sheet to display

getHeadElements

public List<Element> getHeadElements()
Return the TabbedForm HTML HEAD elements for the following resources: Additionally all the Form import statements are also returned.

Specified by:
getHeadElements in interface Control
Overrides:
getHeadElements in class Form
Returns:
the control list of HEAD elements to be included in the page
See Also:
Control.getHeadElements()

getTabHeight

public String getTabHeight()
Return the tab sheet height HTML attribute value.

Returns:
the tab sheet height attribute value

setTabHeight

public void setTabHeight(String value)
Set the tab sheet height HTML attribute value.

Parameters:
value - the tab sheet height attribute value

getTabSheets

public List<FieldSet> getTabSheets()
Return list FieldSet tab sheets.

Returns:
list FieldSet tab sheets

getTabSheetNumber

public int getTabSheetNumber(String fieldName)
Return the tab sheet number for the given field name, indexed from 1. If the field is not found this method will return 1.

Parameters:
fieldName - the name of the form field
Returns:
the tab sheet number for the given field (indexed from 1)

getTabWidth

public String getTabWidth()
Return the tab sheet width HTML attribute value.

Returns:
the tab sheet width attribute value

setTabWidth

public void setTabWidth(String value)
Set the tab sheet width HTML attribute value.

Parameters:
value - the tab sheet width attribute value

getTemplate

public String getTemplate()
Return the path of the Velocity template to render.

Returns:
the path of the Velocity template to render

setTemplate

public void setTemplate(String template)
Set the path of the Velocity template to render.

Parameters:
template - the path of the Velocity template to render

onProcess

public boolean onProcess()
Process the Form request. In addition to the normal Form onProcess() processing, if the Form is invalid this method will display the tab sheet with the first field error.

Specified by:
onProcess in interface Control
Overrides:
onProcess in class Form
Returns:
true to continue Page event processing or false otherwise

render

public void render(HtmlStringBuffer buffer)
Render the HTML representation of the TabbedForm.

Specified by:
render in interface Control
Overrides:
render in class Form
Parameters:
buffer - the specified buffer to render the control's output to
See Also:
toString()

toString

public String toString()
Return the HTML string representation of the form. The form will be rendered using the classpath template:
 /org/apache/click/extras/control/TabbedForm.htm 
If the form contains errors after processing, these errors will be rendered.

Overrides:
toString in class AbstractContainer
Returns:
the HTML string representation of the form

renderValidationJavaScript

protected void renderValidationJavaScript(HtmlStringBuffer buffer,
                                          List<Field> formFields)
Overrides:
renderValidationJavaScript in class Form