Class CmsForm
java.lang.Object
org.opencms.gwt.client.ui.input.form.CmsForm
This class acts as a container for form fields.
It is also responsible for collecting and validating the values of the form fields.
- Since:
- 8.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe set of fields which have been edited.protected Map<String, I_CmsFormField> A map from field ids to the corresponding widgets.protected I_CmsFormHandlerThe form handler.protected booleanA flag which indicates whether the user has pressed enter in a widget. -
Constructor Summary
ConstructorsConstructorDescriptionCmsForm(boolean initPanel) Creates a new form and optionally sets the form widget container to a simple form field panel.CmsForm(A_CmsFormFieldPanel panel) Creates a new form with an existing form widget container. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddField(String fieldGroup, I_CmsFormField formField) Adds a form field to the form.voidaddField(String fieldGroup, I_CmsFormField formField, String initialValue) Adds a form field to the form and sets its initial value.voidaddField(I_CmsFormField field, String initialValue) Adds a form field.voidaddResetHandler(I_CmsFormResetHandler handler) Adds a new form reset handler to the form.Collects all values from the form fields.protected StringReturns the configuration string for the server side form validator.protected voiddefaultHandleKeyPress(I_CmsFormField field, int keyCode) The default keypress event handling function for form fields.protected voiddefaultHandleValueChange(I_CmsFormField field, String newValue, boolean inhibitValidation) Default handler for value change events of form fields.Returns the set of names of fields which have been edited by the user in the current form.Returns the form field with a given id.Returns a map of this form's field, indexed by their field name.protected Collection<I_CmsFormField> getFieldsByModelId(String modelId) Gets the fields with a given model id.Returns the field group ids of the form.Returns the form widget container.voidhandleSubmit(I_CmsFormSubmitHandler handler) Passes this form's data to a form submit handler.booleanChecks that no fields are invalid.booleannoFieldsInvalid(Collection<I_CmsFormField> fields) Returns true if none of the fields in a collection are marked as invalid.voidremoveGroup(String group) Removes all fields for the given group.voidrender()Renders all fields.voidrenderGroup(String group) Renders the fields of the given group.voidsetFormHandler(I_CmsFormHandler handler) Sets the form handler for this form.voidsetValidatorClass(String validatorClass) Sets the server-side form validator class to use.voidsetWidget(A_CmsFormFieldPanel widget) Sets the form widget container.protected voidupdateFieldValidationStatus(String fieldId, org.opencms.gwt.shared.CmsValidationResult result) Applies a validation result to a form field.protected voidupdateFieldValidationStatus(I_CmsFormField field, org.opencms.gwt.shared.CmsValidationResult result) Updates the field validation status.protected voidupdateModelValidationStatus(String modelId, org.opencms.gwt.shared.CmsValidationResult result) Updates the model validation status.voidPerforms an initial validation of all form fields.voidValidates the form fields and submits their values if the validation was successful.voidvalidateField(I_CmsFormField field) Validates a single field.
-
Field Details
-
m_editedFields
The set of fields which have been edited. -
m_fields
A map from field ids to the corresponding widgets. -
m_formHandler
The form handler. -
m_pressedEnter
A flag which indicates whether the user has pressed enter in a widget.
-
-
Constructor Details
-
CmsForm
Creates a new form with an existing form widget container.- Parameters:
panel- the form widget container
-
CmsForm
Creates a new form and optionally sets the form widget container to a simple form field panel.- Parameters:
initPanel- if true, initializes the form widget container
-
-
Method Details
-
addField
Adds a form field.- Parameters:
field- the field to addinitialValue- the initial field value
-
addField
Adds a form field to the form.- Parameters:
fieldGroup- the form field group keyformField- the form field which should be added
-
addField
Adds a form field to the form and sets its initial value.- Parameters:
fieldGroup- the form field group keyformField- the form field which should be addedinitialValue- the initial value of the form field, or null if the field shouldn't have an initial value
-
addResetHandler
Adds a new form reset handler to the form.- Parameters:
handler- the new form reset handler
-
collectValues
Collects all values from the form fields.This method omits form fields whose values are null.
- Returns:
- a map of the form field values
-
getEditedFields
Returns the set of names of fields which have been edited by the user in the current form.- Returns:
- the set of names of fields edited by the user
-
getField
Returns the form field with a given id.- Parameters:
id- the id of the form field- Returns:
- the form field with the given id, or null if no field was found
-
getFields
Returns a map of this form's field, indexed by their field name.- Returns:
- a map of form fields
-
getGroups
Returns the field group ids of the form.- Returns:
- the field groups
-
getWidget
Returns the form widget container.- Returns:
- the form widget container
-
handleSubmit
Passes this form's data to a form submit handler.- Parameters:
handler- the form submit handler
-
noFieldsInvalid
Checks that no fields are invalid.- Returns:
- true if no fields are invalid.
-
noFieldsInvalid
Returns true if none of the fields in a collection are marked as invalid.- Parameters:
fields- the form fields- Returns:
- true if none of the fields are invalid
-
removeGroup
Removes all fields for the given group.- Parameters:
group- the group for which the fields should be removed
-
render
Renders all fields. -
renderGroup
Renders the fields of the given group.- Parameters:
group- the field group
-
setFormHandler
Sets the form handler for this form.- Parameters:
handler- the form handler
-
setValidatorClass
Sets the server-side form validator class to use.- Parameters:
validatorClass- the form validator class name
-
setWidget
Sets the form widget container.- Parameters:
widget- the form widget container
-
validateAllFields
Performs an initial validation of all form fields. -
validateAndSubmit
Validates the form fields and submits their values if the validation was successful. -
validateField
Validates a single field.- Parameters:
field- the field to validate
-
createValidatorConfig
Returns the configuration string for the server side form validator.- Returns:
- the form validator configuration string
-
defaultHandleKeyPress
The default keypress event handling function for form fields.- Parameters:
field- the form field for which the event has been firedkeyCode- the key code
-
defaultHandleValueChange
protected void defaultHandleValueChange(I_CmsFormField field, String newValue, boolean inhibitValidation) Default handler for value change events of form fields.- Parameters:
field- the form field for which the event has been firednewValue- the new valueinhibitValidation- prevents validation of the edited field
-
getFieldsByModelId
Gets the fields with a given model id.- Parameters:
modelId- the model id- Returns:
- the fields with the given model id
-