Class CmsForm
- java.lang.Object
-
- org.opencms.gwt.client.ui.input.form.CmsForm
-
public class CmsForm extends java.lang.Object
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
Fields Modifier and Type Field Description protected java.util.Set<java.lang.String>
m_editedFields
The set of fields which have been edited.protected java.util.Map<java.lang.String,I_CmsFormField>
m_fields
A map from field ids to the corresponding widgets.protected I_CmsFormHandler
m_formHandler
The form handler.protected boolean
m_pressedEnter
A flag which indicates whether the user has pressed enter in a widget.
-
Constructor Summary
Constructors Constructor Description CmsForm(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addField(java.lang.String fieldGroup, I_CmsFormField formField)
Adds a form field to the form.void
addField(java.lang.String fieldGroup, I_CmsFormField formField, java.lang.String initialValue)
Adds a form field to the form and sets its initial value.void
addField(I_CmsFormField field, java.lang.String initialValue)
Adds a form field.void
addResetHandler(I_CmsFormResetHandler handler)
Adds a new form reset handler to the form.java.util.Map<java.lang.String,java.lang.String>
collectValues()
Collects all values from the form fields.protected java.lang.String
createValidatorConfig()
Returns the configuration string for the server side form validator.protected void
defaultHandleKeyPress(I_CmsFormField field, int keyCode)
The default keypress event handling function for form fields.protected void
defaultHandleValueChange(I_CmsFormField field, java.lang.String newValue, boolean inhibitValidation)
Default handler for value change events of form fields.java.util.Set<java.lang.String>
getEditedFields()
Returns the set of names of fields which have been edited by the user in the current form.I_CmsFormField
getField(java.lang.String id)
Returns the form field with a given id.java.util.Map<java.lang.String,I_CmsFormField>
getFields()
Returns a map of this form's field, indexed by their field name.protected java.util.Collection<I_CmsFormField>
getFieldsByModelId(java.lang.String modelId)
Gets the fields with a given model id.java.util.Collection<java.lang.String>
getGroups()
Returns the field group ids of the form.A_CmsFormFieldPanel
getWidget()
Returns the form widget container.void
handleSubmit(I_CmsFormSubmitHandler handler)
Passes this form's data to a form submit handler.boolean
noFieldsInvalid()
Checks that no fields are invalid.boolean
noFieldsInvalid(java.util.Collection<I_CmsFormField> fields)
Returns true if none of the fields in a collection are marked as invalid.void
removeGroup(java.lang.String group)
Removes all fields for the given group.void
render()
Renders all fields.void
renderGroup(java.lang.String group)
Renders the fields of the given group.void
setFormHandler(I_CmsFormHandler handler)
Sets the form handler for this form.void
setValidatorClass(java.lang.String validatorClass)
Sets the server-side form validator class to use.void
setWidget(A_CmsFormFieldPanel widget)
Sets the form widget container.protected void
updateFieldValidationStatus(java.lang.String fieldId, org.opencms.gwt.shared.CmsValidationResult result)
Applies a validation result to a form field.protected void
updateFieldValidationStatus(I_CmsFormField field, org.opencms.gwt.shared.CmsValidationResult result)
Updates the field validation status.protected void
updateModelValidationStatus(java.lang.String modelId, org.opencms.gwt.shared.CmsValidationResult result)
Updates the model validation status.void
validateAllFields()
Performs an initial validation of all form fields.void
validateAndSubmit()
Validates the form fields and submits their values if the validation was successful.void
validateField(I_CmsFormField field)
Validates a single field.
-
-
-
Field Detail
-
m_editedFields
protected java.util.Set<java.lang.String> m_editedFields
The set of fields which have been edited.
-
m_fields
protected java.util.Map<java.lang.String,I_CmsFormField> m_fields
A map from field ids to the corresponding widgets.
-
m_formHandler
protected I_CmsFormHandler m_formHandler
The form handler.
-
m_pressedEnter
protected boolean m_pressedEnter
A flag which indicates whether the user has pressed enter in a widget.
-
-
Constructor Detail
-
CmsForm
public CmsForm(A_CmsFormFieldPanel panel)
Creates a new form with an existing form widget container.- Parameters:
panel
- the form widget container
-
CmsForm
public CmsForm(boolean initPanel)
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 Detail
-
addField
public void addField(I_CmsFormField field, java.lang.String initialValue)
Adds a form field.- Parameters:
field
- the field to addinitialValue
- the initial field value
-
addField
public void addField(java.lang.String fieldGroup, I_CmsFormField formField)
Adds a form field to the form.- Parameters:
fieldGroup
- the form field group keyformField
- the form field which should be added
-
addField
public void addField(java.lang.String fieldGroup, I_CmsFormField formField, java.lang.String initialValue)
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
public void addResetHandler(I_CmsFormResetHandler handler)
Adds a new form reset handler to the form.- Parameters:
handler
- the new form reset handler
-
collectValues
public java.util.Map<java.lang.String,java.lang.String> 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
public java.util.Set<java.lang.String> 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
public I_CmsFormField getField(java.lang.String id)
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
public java.util.Map<java.lang.String,I_CmsFormField> getFields()
Returns a map of this form's field, indexed by their field name.- Returns:
- a map of form fields
-
getGroups
public java.util.Collection<java.lang.String> getGroups()
Returns the field group ids of the form.- Returns:
- the field groups
-
getWidget
public A_CmsFormFieldPanel getWidget()
Returns the form widget container.- Returns:
- the form widget container
-
handleSubmit
public void handleSubmit(I_CmsFormSubmitHandler handler)
Passes this form's data to a form submit handler.- Parameters:
handler
- the form submit handler
-
noFieldsInvalid
public boolean noFieldsInvalid()
Checks that no fields are invalid.- Returns:
- true if no fields are invalid.
-
noFieldsInvalid
public boolean noFieldsInvalid(java.util.Collection<I_CmsFormField> fields)
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
public void removeGroup(java.lang.String group)
Removes all fields for the given group.- Parameters:
group
- the group for which the fields should be removed
-
render
public void render()
Renders all fields.
-
renderGroup
public void renderGroup(java.lang.String group)
Renders the fields of the given group.- Parameters:
group
- the field group
-
setFormHandler
public void setFormHandler(I_CmsFormHandler handler)
Sets the form handler for this form.- Parameters:
handler
- the form handler
-
setValidatorClass
public void setValidatorClass(java.lang.String validatorClass)
Sets the server-side form validator class to use.- Parameters:
validatorClass
- the form validator class name
-
setWidget
public void setWidget(A_CmsFormFieldPanel widget)
Sets the form widget container.- Parameters:
widget
- the form widget container
-
validateAllFields
public void validateAllFields()
Performs an initial validation of all form fields.
-
validateAndSubmit
public void validateAndSubmit()
Validates the form fields and submits their values if the validation was successful.
-
validateField
public void validateField(I_CmsFormField field)
Validates a single field.- Parameters:
field
- the field to validate
-
createValidatorConfig
protected java.lang.String createValidatorConfig()
Returns the configuration string for the server side form validator.- Returns:
- the form validator configuration string
-
defaultHandleKeyPress
protected void defaultHandleKeyPress(I_CmsFormField field, int keyCode)
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, java.lang.String newValue, boolean inhibitValidation)
Default handler for value change events of form fields.- Parameters:
field
- the form field for which the event has been firedinhibitValidation
- prevents validation of the edited fieldnewValue
- the new value
-
getFieldsByModelId
protected java.util.Collection<I_CmsFormField> getFieldsByModelId(java.lang.String modelId)
Gets the fields with a given model id.- Parameters:
modelId
- the model id- Returns:
- the fields with the given model id
-
updateFieldValidationStatus
protected void updateFieldValidationStatus(I_CmsFormField field, org.opencms.gwt.shared.CmsValidationResult result)
Updates the field validation status.- Parameters:
field
- the form fieldresult
- the validation result
-
updateFieldValidationStatus
protected void updateFieldValidationStatus(java.lang.String fieldId, org.opencms.gwt.shared.CmsValidationResult result)
Applies a validation result to a form field.- Parameters:
fieldId
- the field id to which the validation result should be appliedresult
- the result of the validation operation
-
updateModelValidationStatus
protected void updateModelValidationStatus(java.lang.String modelId, org.opencms.gwt.shared.CmsValidationResult result)
Updates the model validation status.- Parameters:
modelId
- the model idresult
- the validation result
-
-