| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.click.control.AbstractControl
org.apache.click.control.AbstractContainer
org.apache.click.control.Form
public class Form
Provides a Form control: <form method='post'>.
| 
 | 
Field controls
 in the order they were added to the form, and then it will process the
 Button controls in the added order. Once all the Fields have been
 processed the form will invoke its action listener if defined.
 
 public class Login extends Page {
     public Form form = new Form();
     public Login() {
         form.add(new TextField("username", true));
         form.add(new PasswordField("password", true));
         form.add(new Submit("ok", "  OK  ", this, "onOkClick"));
         form.add(new Submit("cancel", this, "onCancelClick"));
     }
     public boolean onOkClick() {
         if (form.isValid()) {
             User user = new User();
             form.copyTo(user);
             if (getUserService().isAuthenticatedUser(user)) {
                 getContext().setSessionAttribute("user", user);
                 setRedirect(HomePage.class);
             } else {
                 form.setError(getMessage("authentication-error"));
             }
         }
         return true;
     }
     public boolean onCancelClick() {
         setRedirect(WelcomePage.class);
         return false;
     }
 } 
 The forms corresponding template code is below. Note the form automatically
 renders itself when Velocity invokes its AbstractContainer.toString() method.
 
 $form 
 If a Form has been posted and processed, if it has an error defined or
 any of its Fields have validation errors they will be automatically
 rendered, and the isValid() method will return false.
 
 copyFrom(Object)copyTo(Object)
 // The customer.address.state field
 TextField stateField = new TextField("address.state");
 form.add(stateField);
 ..
 // Loads the customer address state into the form stateField
 Customer customer = getCustomer();
 form.copyFrom(customer);
 ..
 // Copies form stateField value into the customer address state
 Customer customer = new Customer();
 form.copyTo(customer); 
 When populating an object from a form post Click will automatically create
 any null nested objects so their properties can be set. To do this Click
 uses the no-args constructor of the nested objects class.
 
 copyTo(Object) and copyFrom(Object) also supports
 java.util.Map as an argument. Examples of using
 java.util.Map are shown in the respective method descriptions.
 
 setValidate(boolean) to false.
 
 Form also provides a validate() method where subclasses can provide
 custom cross-field validation.
 
 File Upload Validation
 
 The Form's validateFileUpload() provides validation for multipart
 requests (multipart requests are used for uploading files from the browser).
 The validateFileUpload() method checks that files being uploaded do not exceed the
 maximum request size
 or the maximum file size.
 
 Note: if the maximum request size or maximum file size
 is exceeded, the request is deemed invalid (hasPostError
 will return true), and no further processing is performed on the form or fields.
 Instead the form will display the appropriate error message for the invalid request.
 See validateFileUpload() for details of the error message properties.
 
 JavaScript Validation
 
 The Form control also supports client side JavaScript validation. By default
 JavaScript validation is not enabled. To enable JavaScript validation set
 setJavaScriptValidation(boolean) to true. For example:
 
 Form form = new Form("form");
 form.setJavaScriptValidation(true);
 // Add form fields
 ..
 form.add(new Submit("ok", " OK ", this, "onOkClicked");
 Submit cancel = new Submit("cancel", "Cancel", this, "onCancelClicked");
 cancel.setCancelJavaScriptValidation(true);
 addControl(form); 
 Please note in that is this example the cancel submit button has
 Submit.setCancelJavaScriptValidation(boolean) set to true. This
 prevents JavaScript form validation being performed when the cancel button is
 clicked.
 
 <html> <head> $headElements </head> <body> $form $jsElements </body> </html>
| buttonAlign | button alignment: ["left", "center", "right"] | 
| buttonStyle | button <td> "style" attribute value | 
| columns | number of form table columns, the default value number is 1 | 
| errorsAlign | validation error messages alignment: ["left", "center", "right"] | 
| errorsPosition | validation error messages position: ["top", "middle", "bottom"] | 
| errorsStyle | errors <td> "style" attribute value | 
| fieldStyle | field <td> "style" attribute value | 
| labelAlign | field label alignment: ["left", "center", "right"] | 
| labelsPosition | label position relative to field: ["left", "top"] | 
| labelStyle | label <td> "style" attribute value | 
| click/control.css | control CSS styles, automatically deployed to the click web directory | 
| /click-control.properties | form and field messages and HTML, located under classpath | 
 $form.fields.usernameField 
 Whenever including your own Form markup in a page template or Velocity macro
 always specify:
 AbstractControl.name of the Form startTag() and endTag()
 methods to render this information.
 
 An example of a manually laid out Login form is provided below:
 $form.startTag() <table style="margin: 1em;"> #if ($form.error) <tr> <td colspan="2" style="color: red;"> $form.error </td> </tr> #end #if ($form.fields.usernameField.error) <tr> <td colspan="2" style="color: red;"> $form.fields.usernameField.error </td> </tr> #end #if ($form.fields.passwordField.error) <tr> <td colspan="2" style="color: red;"> $form.fields.passwordField.error </td> </tr> #end <tr> <td> Username: </td> <td> $form.fields.usernameField </td> </tr> <tr> <td> Password: </td> <td> $form.fields.passwordField </td> </tr> <tr> <td> $form.fields.okSubmit $form.fields.cancelSubmit </td> </tr> </table> $form.endTag()As you can see in this example most of the code and markup is generic and could be reused. This is where Velocity Macros come in.
getFieldList() and
 getButtonList() properties within a Velocity macro. If you want to
 access all Form Controls from within a Velocity template or macro use
 AbstractContainer.getControls().
 
 The example below provides a generic writeForm()
 macro which you could use through out an application. This Velocity macro code
 would be contained in a macro file, e.g. macro.vm.
 #* Custom Form Macro Code *# #macro( writeForm[$form] ) $form.startTag() <table width="100%"> #if ($form.error) <tr> <td colspan="2" style="color: red;"> $form.error </td> </tr> #end #foreach ($field in $form.fieldList) #if (!$field.hidden) #if (!$field.valid) <tr> <td colspan="2"> $field.error </td> </tr> #end <tr> <td> $field.label: </td><td> $field </td> </tr> #end #end <tr> <td colspan="2"> #foreach ($button in $form.buttonList) $button   #end </td> </tr> </table> $form.endTag() #endYou would then call this macro in your Page template passing it your form object:
#writeForm($form)At render time Velocity will execute the macro using the given form and render the results to the response output stream.
onSubmitCheck(org.apache.click.Page, String) methods. For example:
 
 public class Purchase extends Page {
     ..
     public boolean onSecurityCheck() {
         return form.onSubmitCheck(this, "/invalid-submit.html");
     }
 } 
 The form submit check methods store a special token in the users session
 and in a hidden field in the form to ensure a form post isn't replayed.
 
 setValidate(boolean)
 to switch off form and field validation. For example:
 
 public void onInit() {
     checkbox.setAttribute("onclick", "form.submit()");
     // Since onInit occurs before the onProcess event,
     // we have to explicitly bind the submit button in the onInit event if we
     // want to check if it was clicked.
     // If the submit button wasn't clicked it means the Form was submitted
     // using JavaScript and we don't want to validate yet
     ClickUtils.bind(submit);
     // If submit was not clicked, don't validate
     if(form.isFormSubmission() && !submit.isClicked()) {
         form.setValidate(false);
     }
 } 
 See also the W3C HTML reference: FORM
Field, 
Submit, 
Serialized Form| Field Summary | |
|---|---|
| protected  String | actionURLThe form action URL. | 
| static String | ALIGN_CENTERThe align center, form layout constant: "center". | 
| static String | ALIGN_LEFTThe align left, form layout constant: "left". | 
| static String | ALIGN_RIGHTThe align right, form layout constant: "right". | 
| protected  String | buttonAlignThe button align, default value is "left". | 
| protected  List<Button> | buttonListThe ordered list of button values. | 
| protected  String | buttonStyleThe button <td> "style" attribute value. | 
| protected  int | columnsThe number of form layout table columns, default value: 1. | 
| protected  int | defaultFieldSizeThe default field size, default value: 0. | 
| protected  boolean | disabledThe form disabled value. | 
| protected  String | enctypeThe form "enctype" attribute. | 
| protected  String | errorThe form level error message. | 
| protected  String | errorsAlignThe errors block align, default value is "left". | 
| protected  String | errorsPositionThe form errors position ["top", "middle", "bottom"] default value: "top". | 
| protected  String | errorsStyleThe error <td> "style" attribute value. | 
| protected  List<Field> | fieldListThe ordered list of fields, excluding buttons. | 
| protected  String | fieldStyleThe field <td> "style" attribute value. | 
| protected  Map<String,Integer> | fieldWidthsThe map of field width values. | 
| protected static String | FOCUS_JAVASCRIPTThe Form set field focus JavaScript. | 
| static String | FORM_NAMEThe form name parameter for multiple forms: "form_name". | 
| protected  Boolean | formSubmissionFlag indicating whether this form was submitted. | 
| protected  boolean | javaScriptValidationThe JavaScript client side form fields validation flag. | 
| protected  String | labelAlignThe label align, default value is "left". | 
| protected  String | labelsPositionThe form labels position ["left", "top"] default value: "left". | 
| protected  String | labelStyleThe label <td> "style" attribute value. | 
| protected  String | methodThe form method ["post, "get"], default value: post. | 
| static String | MULTIPART_FORM_DATAThe HTTP content type header for multipart forms. | 
| static String | POSITION_BOTTOMThe position bottom, errors on bottom form layout constant: "top". | 
| static String | POSITION_LEFTThe position left, labels of left form layout constant: "left". | 
| static String | POSITION_MIDDLEThe position middle, errors in middle form layout constant: "middle". | 
| static String | POSITION_TOPThe position top, errors and labels form layout constant: "top". | 
| protected  boolean | readonlyThe form is readonly flag. | 
| static String | SUBMIT_CHECKThe submit check reserved request parameter prefix: SUBMIT_CHECK_. | 
| protected  boolean | validateThe form validate fields when processing flag. | 
| 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 | |
|---|---|
| Form()Create a form with no name. | |
| Form(String name)Create a form with the given name. | |
| Method Summary | |
|---|---|
|  Control | add(Control control)Add a Control to the form and return the added instance. | 
|  Control | add(Control control,
    int width)Add the control to the form and specify the control's width in columns. | 
|  Field | add(Field field)Add the field to the form, and set the fields form property. | 
|  Field | add(Field field,
    int width)Add the field to the form and specify the field's width in columns. | 
|  void | clearErrors()Clear any form or field errors by setting them to null. | 
|  void | clearValues()Clear all the form field values setting them to null. | 
|  void | copyFrom(Object object)Copy the given object's attributes into the Form's field values. | 
|  void | copyFrom(Object object,
         boolean debug)Copy the given object's attributes into the Form's field values. | 
|  void | copyTo(Object object)Copy the Form's field values into the given object's attributes. | 
|  void | copyTo(Object object,
       boolean debug)Copy the Form's field values into the given object's attributes. | 
|  String | endTag()Return the rendered form end tag and JavaScript for field focus and validation. | 
|  String | getActionURL()Return the form "action" attribute URL value. | 
|  String | getButtonAlign()Return the buttons <td> HTML horizontal alignment: "left", "center", "right". | 
|  List<Button> | getButtonList()Return the ordered list of Buttons. | 
|  String | getButtonStyle()Return the button <td> "style" attribute value. | 
|  int | getColumns()Return the number of form layout table columns. | 
|  int | getControlSizeEst()Return the estimated rendered control size in characters. | 
|  int | getDefaultFieldSize()Return the form default field size. | 
|  String | getEnctype()Return the form "enctype" attribute value, or null if not defined. | 
|  String | getError()Return the form level error message. | 
|  List<Field> | getErrorFields()Return a list of form fields which are not valid, not hidden and not disabled. | 
|  String | getErrorsAlign()Return the errors block HTML horizontal alignment: "left", "center", "right". | 
|  String | getErrorsPosition()Return the form errors position ["top", "middle", "bottom"]. | 
|  String | getErrorsStyle()Return the error <td> "style" attribute value. | 
|  Field | getField(String name)Return the named field if contained in the form or null if not found. | 
|  List<Field> | getFieldList()Return the ordered list of form fields, excluding buttons. | 
|  Map<String,Control> | getFields()Return the Map of form fields (including buttons), keyed on field name. | 
|  String | getFieldStyle()Return the field <td> "style" attribute value. | 
|  String | getFieldValue(String name)Return the field value for the named field, or null if the field is not found. | 
|  Map<String,Integer> | getFieldWidths()Return the map of field width values, keyed on field name. | 
| protected  int | getFormSizeEst(List<Field> formFields)Return the estimated rendered form size in characters. | 
|  List<Element> | getHeadElements()Return the Form HEAD elements to be included in the page. | 
|  boolean | getJavaScriptValidation()Deprecated. use isJavaScriptValidation()instead | 
|  String | getLabelAlign()Return the field label HTML horizontal alignment: "left", "center", "right". | 
|  String | getLabelsPosition()Return the form labels position ["left", "top"]. | 
|  String | getLabelStyle()Return the label <td> "style" attribute value. | 
|  String | getMethod()Return the form method ["post" | "get"], default value is post. | 
|  Object | getState()Return the form state. | 
|  String | getTag()Return the form's html tag: form. | 
|  boolean | getValidate()Return true if the Form fields should validate themselves when being processed. | 
| protected  boolean | hasPostError()Returns true if a POST error occurred, false otherwise. | 
|  Control | insert(Control control,
       int index)Add the control to the form at the specified index, and return the added instance. | 
|  boolean | isDisabled()Return true if the form is a disabled. | 
|  boolean | isFormSubmission()Return true if the page request is a submission from this form. | 
|  boolean | isJavaScriptValidation()Return true if JavaScript client side form validation is enabled. | 
|  boolean | isReadonly()Return true if the form is a readonly. | 
|  boolean | isValid()Return true if the fields are valid and there is no form level error, otherwise return false. | 
|  void | onDestroy()Destroy the controls contained in the Form and clear any form error message. | 
|  boolean | onProcess()Process the Form and its child controls only if the Form was submitted by the user. | 
|  boolean | onSubmitCheck(Page page,
              Class<? extends Page> pageClass)Perform a form submission check ensuring the user has not replayed the form submission by using the browser back button. | 
|  boolean | onSubmitCheck(Page page,
              Object submitListener,
              String submitListenerMethod)Perform a form submission check ensuring the user has not replayed the form submission by using the browser back button. | 
|  boolean | onSubmitCheck(Page page,
              String redirectPath)Perform a form submission check ensuring the user has not replayed the form submission by using the browser's back or refresh buttons or by clicking the Form submit button twice, in quick succession. | 
| protected  boolean | performSubmitCheck()Perform a back button submit check, returning true if the request is valid or false otherwise. | 
|  boolean | remove(Control control)Remove the given control from the container, returning true if the control was found in the container and removed, or false if the control was not found. | 
|  boolean | removeField(String name)Remove the named field from the form, returning true if removed or false if not found. | 
|  void | removeFields(List<String> fieldNames)Remove the list of named fields from the form. | 
|  void | removeState(Context context)Remove the Form state from the session for the given request context. | 
|  void | render(HtmlStringBuffer buffer)Render the HTML representation of the Form. | 
| protected  void | renderButtons(HtmlStringBuffer buffer)Render the given list of Buttons to the string buffer. | 
| protected  void | renderControls(HtmlStringBuffer buffer,
               Container container,
               List<Control> controls,
               Map<String,Integer> fieldWidths,
               int columns)Render the specified controls of the container to the string buffer. | 
| protected  void | renderErrors(HtmlStringBuffer buffer,
             boolean processed)Render the form errors to the given buffer is form processed. | 
| protected  void | renderFields(HtmlStringBuffer buffer)Render the non hidden Form Fields to the string buffer. | 
| protected  void | renderFocusJavaScript(HtmlStringBuffer buffer,
                      List<Field> formFields)Render the Form field focus JavaScript to the string buffer. | 
| protected  void | renderHeader(HtmlStringBuffer buffer,
             List<Field> formFields)Render the given form start tag and the form hidden fields to the given buffer. | 
| protected  void | renderTagEnd(List<Field> formFields,
             HtmlStringBuffer buffer)Close the form tag and render any additional content after the Form. | 
| protected  void | renderValidationJavaScript(HtmlStringBuffer buffer,
                           List<Field> formFields)Render the Form validation JavaScript to the string buffer. | 
|  Control | replace(Control currentControl,
        Control newControl)Deprecated. this method was used for stateful pages, which have been deprecated | 
|  void | restoreState(Context context)Restore the Form state from the session for the given request context. | 
|  void | saveState(Context context)Save the Form state to the session for the given request context. | 
|  void | setActionURL(String value)Return the form "action" attribute URL value. | 
|  void | setButtonAlign(String align)Set the button <td> HTML horizontal alignment: "left", "center", "right". | 
|  void | setButtonStyle(String value)Set the button <td> "style" attribute value. | 
|  void | setColumns(int columns)Set the number of form layout table columns. | 
|  void | setDefaultFieldSize(int size)Return the form default field size. | 
|  void | setDisabled(boolean disabled)Set the form disabled flag. | 
|  void | setEnctype(String enctype)Set the form "enctype" attribute value. | 
|  void | setError(String error)Set the form level validation error message. | 
|  void | setErrorsAlign(String align)Set the errors block HTML horizontal alignment: "left", "center", "right". | 
|  void | setErrorsPosition(String position)Set the form errors position ["top", "middle", "bottom"]. | 
|  void | setErrorsStyle(String value)Set the errors <td> "style" attribute value. | 
|  void | setFieldStyle(String value)Set the field <td> "style" attribute value. | 
|  void | setJavaScriptValidation(boolean validate)Set the JavaScript client side form validation flag. | 
|  void | setLabelAlign(String align)Set the field label HTML horizontal alignment: "left", "center", "right". | 
|  void | setLabelsPosition(String position)Set the form labels position ["left", "top"]. | 
|  void | setLabelStyle(String value)Set the label <td> "style" attribute value. | 
|  void | setListener(Object listener,
            String method)The callback listener will only be called during processing if the field value is valid. | 
|  void | setMethod(String value)Set the form method ["post" | "get"]. | 
|  void | setName(String name)Set the name of the form. | 
|  void | setReadonly(boolean readonly)Set the form readonly flag. | 
|  void | setState(Object state)Set the Form state. | 
|  void | setValidate(boolean validate)Set the Form field validation flag, telling the Fields to validate themselves when their onProcess() method is invoked. | 
|  String | startTag()Return the rendered opening form tag and all the forms hidden fields. | 
|  void | validate()The validate method is invoked by onProcess()to validate
 the request submission. | 
| protected  void | validateFileUpload()Validate the request for any file upload (multipart) errors. | 
| Methods inherited from class org.apache.click.control.AbstractContainer | 
|---|
| contains, getControl, getControlMap, getControls, hasControls, onInit, onRender, renderChildren, renderContent, renderTagEnd, toString | 
| 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 | 
|---|
public static final String ALIGN_LEFT
public static final String ALIGN_CENTER
public static final String ALIGN_RIGHT
public static final String POSITION_TOP
public static final String POSITION_MIDDLE
public static final String POSITION_BOTTOM
public static final String POSITION_LEFT
public static final String FORM_NAME
public static final String MULTIPART_FORM_DATA
public static final String SUBMIT_CHECK
protected static final String FOCUS_JAVASCRIPT
protected String actionURL
protected boolean disabled
protected String enctype
protected String error
protected final List<Field> fieldList
protected String method
protected boolean readonly
protected boolean validate
protected String buttonAlign
protected final List<Button> buttonList
protected String buttonStyle
protected int columns
protected int defaultFieldSize
protected String errorsAlign
protected String errorsPosition
protected String errorsStyle
protected String fieldStyle
protected Map<String,Integer> fieldWidths
protected Boolean formSubmission
protected boolean javaScriptValidation
protected String labelAlign
protected String labelsPosition
protected String labelStyle
| Constructor Detail | 
|---|
public Form(String name)
name - the name of the form
IllegalArgumentException - if the form name is nullpublic Form()
| Method Detail | 
|---|
public Control insert(Control control,
                      int index)
replaced
 by the given control. If a control has no name defined it cannot be replaced.
 
 Controls can be retrieved from the Map controlMap
 where the key is the Control name and value is the Control instance.
 
 All controls are available on the controls list
 at the index they were inserted. If you are only interested in Fields,
 note that Buttons are available on the buttonList
 while other fields are available on fieldList.
 
 The specified index only applies to controls, not
 buttonList or fieldList.
 
 Please note if the specified control already has a parent assigned,
 it will automatically be removed from that parent and inserted into the
 form.
insert in interface Containerinsert in class AbstractContainercontrol - the control to add to the containerindex - the index at which the control is to be inserted
IllegalArgumentException - if the control is null or if the control
 and container is the same instance or if the Field name is not defined
IndexOutOfBoundsException - if index is out of range
 (index < 0 || index > getControls().size())Container.insert(org.apache.click.Control, int)public Control add(Control control)
replaced
 by the given control. If a control has no name defined it cannot be replaced.
 
 Controls can be retrieved from the Map controlMap
 where the key is the Control name and value is the Control instance.
 
 All controls are available on the controls list
 in the order they were added. If you are only interested in Fields,
 note that Buttons are available on the buttonList
 while other fields are available on fieldList.
add in interface Containeradd in class AbstractContainercontrol - the control to add to the container and return
IllegalArgumentException - if the control is null, the Control name
 is not defined or the container already contains a control with the same
 nameContainer.add(org.apache.click.Control)public Field add(Field field)
replaced
 by the given control. If a control has no name defined it cannot be replaced.
 
 Fields can be retrieved from the Map fields where
 the key is the Field name and value is the Field instance.
 
 Buttons are available on the buttonList while
 other fields are available on fieldList.
field - the field to add to the form
IllegalArgumentException - if the field is null, the field name
 is not defined or the form already contains a control with the same nameadd(org.apache.click.Control)
public Field add(Field field,
                 int width)
replaced
 by the given control. If a control has no name defined it cannot be replaced.
 
 Fields can be retrieved from the Map fields where
 the key is the Field name and value is the Field instance.
 
 Fields are available on fieldList.
 
 Note Button and HiddenField types are not valid arguments for this method.
field - the field to add to the formwidth - the width of the field in table columns
IllegalArgumentException - if the field is null, field name is
 not defined, field is a Button or HiddenField, the form already contains
 a field with the same name or the width < 1add(org.apache.click.Control)
public Control add(Control control,
                   int width)
replaced
 by the given control. If a control has no name defined it cannot be replaced.
 
 Controls can be retrieved from the Map controlMap
 where the key is the Control name and value is the Control instance.
 
 Controls are available on the controls list.
 
 Note Button and HiddenField types are not valid arguments for this method.
control - the control to add to the formwidth - the width of the control in table columns
IllegalArgumentException - if the control is null, control is a
 Button or HiddenField, the form already contains a control with the same
 name or the width < 1add(org.apache.click.Control)
public Control replace(Control currentControl,
                       Control newControl)
replace in interface Containerreplace in class AbstractContainercurrentControl - the control currently contained in the formnewControl - the control to replace the current control contained in
 the form
IllegalArgumentException - if the currentControl or newControl is
 null
IllegalStateException - if the currentControl is not contained in
 the formContainer.replace(org.apache.click.Control, org.apache.click.Control)public boolean remove(Control control)
Container
remove in interface Containerremove in class AbstractContainercontrol - the control to remove from the container
IllegalArgumentException - if the control is nullContainer.remove(org.apache.click.Control)public boolean removeField(String name)
name - the name of the field to remove from the form
public void removeFields(List<String> fieldNames)
fieldNames - the list of field names to remove from the form
IllegalArgumentException - if any of the fields is nullpublic String getTag()
getTag in class AbstractControlAbstractControl.getTag()public String getActionURL()
public void setActionURL(String value)
value - the form "action" attribute URL valuepublic int getControlSizeEst()
AbstractControl
getControlSizeEst in class AbstractContainerAbstractControl.getControlSizeEst()public boolean isDisabled()
public void setDisabled(boolean disabled)
disabled - the form disabled flagpublic String getEnctype()
public void setEnctype(String enctype)
enctype - the form "enctype" attribute value, or null if not definedpublic String getError()
public void setError(String error)
error - the validation error messagepublic List<Field> getErrorFields()
public Field getField(String name)
name - the name of the field
IllegalStateException - if a non-field control is found with the
 specified namepublic String getFieldValue(String name)
name - the name of the field
public List<Element> getHeadElements()
getHeadElements in interface ControlgetHeadElements in class AbstractControlControl.getHeadElements()public String getMethod()
public void setMethod(String value)
value - the form methodpublic boolean isFormSubmission()
method, for example
   both must be GET or POST
public void setName(String name)
setName in interface ControlsetName in class AbstractControlname - of the control
IllegalArgumentException - if the name is nullControl.setName(String)public boolean isReadonly()
public void setReadonly(boolean readonly)
readonly - the form readonly flagpublic boolean isValid()
public List<Field> getFieldList()
public Map<String,Control> getFields()
AbstractContainer.getControlMap()public boolean getValidate()
public void setValidate(boolean validate)
validate - the Form field validation flagpublic String getButtonAlign()
public void setButtonAlign(String align)
align - the field label HTML horizontal alignmentpublic List<Button> getButtonList()
Buttons.
 
 The order of the buttons is the same order they were added to the form.
 
 The returned list includes only buttons added directly to the Form.
Buttons.public String getButtonStyle()
public void setButtonStyle(String value)
value - the button <td> "style" attribute valuepublic int getColumns()
public void setColumns(int columns)
columns - the number of form layout table columnspublic int getDefaultFieldSize()
public void setDefaultFieldSize(int size)
size - the default field sizepublic String getErrorsAlign()
public void setErrorsAlign(String align)
align - the errors block HTML horizontal alignmentpublic String getErrorsPosition()
public void setErrorsPosition(String position)
position - the form errors positionpublic String getErrorsStyle()
public void setErrorsStyle(String value)
value - the errors <td> "style" attribute valuepublic String getFieldStyle()
public void setFieldStyle(String value)
Field.setParentStyleHint(java.lang.String).
value - the field <td> "style" attribute valueField.setParentStyleHint(java.lang.String), 
Field.setParentStyleClassHint(java.lang.String)public Map<String,Integer> getFieldWidths()
public boolean isJavaScriptValidation()
public boolean getJavaScriptValidation()
isJavaScriptValidation() instead
public void setJavaScriptValidation(boolean validate)
validate - the JavaScript client side validation flagpublic String getLabelAlign()
public void setLabelAlign(String align)
align - the field label HTML horizontal alignmentpublic String getLabelsPosition()
public void setLabelsPosition(String position)
position - the form labels positionpublic String getLabelStyle()
public void setLabelStyle(String value)
Field.setParentStyleHint(java.lang.String) property.
value - the label <td> "style" attribute value
public void setListener(Object listener,
                        String method)
setListener in interface ControlsetListener in class AbstractControllistener - the listener object with the named method to invokemethod - the name of the method to invokeControl.setListener(Object, String)public void clearErrors()
public void clearValues()
public void copyFrom(Object object)
 public void onGet() {
     Long customerId = ..
     Customer customer = CustomerDAO.findByPK(customerId);
     form.copyFrom(customer);
 } 
 copyForm also supports java.util.Map as an argument.
 
 By specifying a map, the Form's field values will be populated by
 matching key/value pairs. A match occurs when the map's key is equal to
 a field's name.
 
 The following example populates the Form fields with a map's
 key/value pairs:
 
 public void onInit() {
     form = new Form("form");
     form.add(new TextField("name"));
     form.add(new TextField("address.street"));
 }
 public void onGet() {
     Map map = new HashMap();
     map.put("name", "Steve");
     map.put("address.street", "12 Long street");
     form.copyFrom(map);
 } 
 For more information on how Fields and Objects are copied see
 ContainerUtils.copyObjectToContainer(java.lang.Object, org.apache.click.control.Container).
object - the object to obtain attribute values from
IllegalArgumentException - if the object parameter is null
public void copyFrom(Object object,
                     boolean debug)
object - the object to obtain attribute values fromdebug - log debug statements when populating the form
IllegalArgumentException - if the object parameter is nullcopyFrom(java.lang.Object)public void copyTo(Object object)
 public void onPost() {
     if (form.isValid()) {
         Customer customer = new Customer();
         form.copyTo(customer);
         ..
     }
     return true;
 } 
 copyTo also supports java.util.Map as an argument.
 
 By specifying a map, the map's key/value pairs are populated from
 matching Form field names. A match occurs when a field's name is
 equal to a map's key.
 
 The following example populates the map with the Form field values:
 
 public void onInit() {
     form = new Form("form");
     form.add(new TextField("name"));
     form.add(new TextField("address.street"));
 }
 public void onGet() {
     Map map = new HashMap();
     map.put("name", null);
     map.put("address.street", null);
     form.copyTo(map);
 } 
 Note that the map acts as a template to specify which fields to populate
 from.
 For more information on how Fields and Objects are copied see
 ContainerUtils.copyContainerToObject(org.apache.click.control.Container, java.lang.Object).
object - the object to populate with field values
IllegalArgumentException - if the object parameter is null
public void copyTo(Object object,
                   boolean debug)
object - the object to populate with field valuesdebug - log debug statements when populating the object
IllegalArgumentException - if the object parameter is nullcopyTo(java.lang.Object)public Object getState()
getState in interface Statefulpublic void setState(Object state)
setState in interface Statefulstate - the Form state to setpublic boolean onProcess()
isFormSubmission() to check whether the form
 was submitted or not.
 
 The Forms processing order is:
 Field controls in the order they were addedButton controls in the order they were addedvalidate() while
 file upload validation are delegated to validateFileUpload().
onProcess in interface ControlonProcess in class AbstractContainerContext.getRequestParameter(String), 
Context.getFileItemMap()public void onDestroy()
onDestroy in interface ControlonDestroy in class AbstractContainerControl.onDestroy()public void validate()
onProcess() to validate
 the request submission. A Form subclass can override this method
 to implement cross-field validation logic.
 
 If the Form determines that the submission is invalid it should set the
 error property with an appropriate error message. For example:
 
 public class RegistrationForm extends Form {
     // Add validation to ensure the password and confirmPassword fields match
     public void validate() {
         String password = getFieldValue("password");
         String confirmPassword = getFieldValue("confirmPassword");
         if (!password.equals(confirmPassword)) {
             // Set Form's error property value that will be shown to the user
             setError("The passwords do not match.");
         }
     }
 } 
public boolean onSubmitCheck(Page page,
                             String redirectPath)
 public class Order extends Page {
     ..
     public boolean onSecurityCheck() {
         return form.onSubmitCheck(this, "/invalid-submit.html");
     }
 } 
 Form submit checks should generally be combined with the Post-Redirect
 pattern which provides a better user experience when pages are refreshed.
 
 Please note: a call to onSubmitCheck always succeeds for Ajax
 requests.
page - the page invoking the Form submit checkredirectPath - the path to redirect invalid submissions to
IllegalArgumentException - if the page or redirectPath is null
public boolean onSubmitCheck(Page page,
                             Class<? extends Page> pageClass)
 public class Order extends Page {
     ..
     public boolean onSecurityCheck() {
         return form.onSubmitCheck(this, InvalidSubmitPage.class);
     }
 } 
 Form submit checks should generally be combined with the Post-Redirect
 pattern which provides a better user experience when pages are refreshed.
 
 Please note: a call to onSubmitCheck always succeeds for Ajax
 requests.
page - the page invoking the Form submit checkpageClass - the page class to redirect invalid submissions to
IllegalArgumentException - if the page or pageClass is null
public boolean onSubmitCheck(Page page,
                             Object submitListener,
                             String submitListenerMethod)
 public class Order extends Page {
     ..
     public boolean onSecurityCheck() {
         return form.onSubmitCheck(his, this, "onInvalidSubmit");
     }
     public boolean onInvalidSubmit() {
        getContext().setRequestAttribute("invalidPath", getPath());
        setForward("invalid-submit.htm");
        return false;
     }
 } 
 Form submit checks should generally be combined with the Post-Redirect
 pattern which provides a better user experience when pages are refreshed.
 
 Please note: a call to onSubmitCheck always succeeds for Ajax
 requests.
page - the page invoking the Form submit checksubmitListener - the listener object to call when an invalid submit
      occurssubmitListenerMethod - the listener method to invoke when an
      invalid submit occurs
IllegalArgumentException - if the page, submitListener or
      submitListenerMethod is nullpublic void removeState(Context context)
context - the request contextsaveState(org.apache.click.Context), 
restoreState(org.apache.click.Context)public void restoreState(Context context)
setState(java.lang.Object) to set the
 form restored state.
context - the request contextsaveState(org.apache.click.Context), 
removeState(org.apache.click.Context)public void saveState(Context context)
getState() to retrieve the form state
 to save.
context - the request contextrestoreState(org.apache.click.Context), 
removeState(org.apache.click.Context)public String startTag()
public String endTag()
public void render(HtmlStringBuffer buffer)
render in interface Controlrender in class AbstractContainerbuffer - the specified buffer to render the control's output toAbstractContainer.toString()protected boolean performSubmitCheck()
protected int getFormSizeEst(List<Field> formFields)
formFields - the list of form fields
protected void renderHeader(HtmlStringBuffer buffer,
                            List<Field> formFields)
buffer - the HTML string buffer to render toformFields - the list of form fieldsprotected void renderFields(HtmlStringBuffer buffer)
renderControls(HtmlStringBuffer, Container, List, Map, int).
buffer - the StringBuffer to render to
protected void renderControls(HtmlStringBuffer buffer,
                              Container container,
                              List<Control> controls,
                              Map<String,Integer> fieldWidths,
                              int columns)
buffer - the StringBuffer to render tocontainer - the container which controls to rendercontrols - the controls to renderfieldWidths - a map of field widths keyed on field namecolumns - the number of form layout table columns
protected void renderErrors(HtmlStringBuffer buffer,
                            boolean processed)
buffer - the string buffer to render the errors toprocessed - the flag indicating whether has been processedprotected void renderButtons(HtmlStringBuffer buffer)
buffer - the StringBuffer to render to
protected void renderTagEnd(List<Field> formFields,
                            HtmlStringBuffer buffer)
formFields - all fields contained within the formbuffer - the buffer to render to
protected void renderFocusJavaScript(HtmlStringBuffer buffer,
                                     List<Field> formFields)
buffer - the StringBuffer to render toformFields - the list of form fields
protected void renderValidationJavaScript(HtmlStringBuffer buffer,
                                          List<Field> formFields)
buffer - the StringBuffer to render toformFields - the list of form fieldsprotected boolean hasPostError()
protected void validateFileUpload()
- /click-control.properties
- file-size-limit-exceeded-error
- post-size-limit-exceeded-error
| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||