Class AbstractFormBuilder
- All Implemented Interfaces:
Cloneable,FormBuilder
- Direct Known Subclasses:
FormBuilderHtml,FormBuilderXml
-
Field Summary
Fields inherited from interface rife.forms.FormBuilder
ID_FORM_FIELD, ID_FORM_LABEL, ID_FORM_NAME, ID_FORM_VALUE, MIDDLE_ATTRIBUTES, PREFIX_FORM_CHECKBOX, PREFIX_FORM_DISPLAY, PREFIX_FORM_HIDDEN, PREFIX_FORM_INPUT, PREFIX_FORM_LABEL, PREFIX_FORM_RADIO, PREFIX_FORM_SECRET, PREFIX_FORM_SELECT, PREFIX_FORM_TEXTAREA, SUFFIX_CHECKED, SUFFIX_SELECTED, TAG_CHECKED, TAG_SELECTED -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Generates a form field for one particular property name.generateField(Template template, Class propertyType, ConstrainedProperty property, String[] values, String prefix) Generates a form field for one particular property.protected Collection<String>generateField(Template template, String templateFieldName, Class propertyType, String name, String[] values, String prefix, ArrayList<String> setValues, boolean replaceExistingValues) protected voidgenerateField(Template template, String templateFieldName, Class propertyType, String name, ConstrainedProperty property, String[] values, ArrayList<String> setValues, boolean replaceExistingValues) protected Collection<String>generateField(Template template, String templateFieldName, Class propertyType, ConstrainedProperty property, String[] values, String prefix, ArrayList<String> setValues, boolean replaceExistingValues) generateField(Template template, String name, String[] values, String prefix) Generates a form field for one particular property name.generateField(Template template, ConstrainedProperty property, String[] values, String prefix) Generates a form field for one particular property.protected abstract voidgenerateFieldCheckbox(Template template, String templateFieldName, Class propertyType, String name, ConstrainedProperty property, String[] values, Template builderTemplate, List<String> setValues, boolean replaceExistingValues) protected voidgenerateFieldCollection(String prefix, boolean singleValue, Template template, String templateFieldName, Class propertyType, String name, ConstrainedProperty property, String[] values, Template builderTemplate, List<String> setValues, boolean replaceExistingValues) protected voidgenerateFieldDisplay(Template template, String templateFieldName, Class propertyType, String name, ConstrainedProperty property, String[] values, Template builderTemplate, ArrayList<String> setValues, boolean replaceExistingValues) protected abstract voidgenerateFieldHidden(Template template, String templateFieldName, String name, ConstrainedProperty property, String[] values, Template builderTemplate, List<String> setValues, boolean replaceExistingValues) protected abstract voidgenerateFieldInput(Template template, String templateFieldName, String name, ConstrainedProperty property, String[] values, Template builderTemplate, List<String> setValues, boolean replaceExistingValues) protected abstract voidgenerateFieldRadio(Template template, String templateFieldName, Class propertyType, String name, ConstrainedProperty property, String[] values, Template builderTemplate, List<String> setValues, boolean replaceExistingValues) protected abstract voidgenerateFieldSecret(Template template, String templateFieldName, String name, ConstrainedProperty property, String[] values, Template builderTemplate, List<String> setValues, boolean replaceExistingValues) protected voidgenerateFieldSelect(Template template, String templateFieldName, Class propertyType, String name, ConstrainedProperty property, String[] values, Template builderTemplate, ArrayList<String> setValues, boolean replaceExistingValues) protected voidgenerateFieldText(String prefix, boolean setValue, boolean valueAsAttribute, boolean limitLength, boolean disableField, boolean requireField, Template template, String templateFieldName, String name, ConstrainedProperty property, String[] values, Template builderTemplate, List<String> setValues, boolean replaceExistingValues) protected abstract voidgenerateFieldTextarea(Template template, String templateFieldName, String name, ConstrainedProperty property, String[] values, Template builderTemplate, List<String> setValues, boolean replaceExistingValues) protected Collection<String>generateForm(Template template, Class beanClass, Object bean, Map<String, String[]> values, String prefix) Generates all the form fields for a bean class.Generates all the form fields for a bean instance.protected voidgenerateFormField(Template template, Constrained constrained, Class propertyType, String propertyName, String[] propertyValues, String prefix, ArrayList<String> setValues) protected StringgenerateLabel(Template template, String templateFieldName, String value) protected abstract Templateprotected abstract Stringprotected abstract Stringprotected abstract Stringprotected abstract Stringprotected abstract Stringprotected abstract Stringprotected abstract Stringprotected abstract Stringprotected abstract Stringprotected abstract Stringprotected abstract Stringprotected abstract Stringabstract ValidationBuilderReturns theValidationBuilderthat is used by thisFormBuilder.protected abstract Stringprotected abstract StringvoidremoveField(Template template, String templateFieldName) Removes the content of the template value that would otherwise be filled in with a generated form field through aFormBuilder.replaceField(rife.template.Template, java.lang.String, rife.validation.ConstrainedProperty, java.lang.String[], java.lang.String)method.voidremoveField(Template template, String name, String prefix) Removes the content of the template value that would otherwise be filled in with a generated form field through aFormBuilder.generateField(rife.template.Template, rife.validation.ConstrainedProperty, java.lang.String[], java.lang.String)method.voidremoveForm(Template template, Class beanClass, String prefix) Removes the content of all the template values that would otherwise be filled in with generated form fields through theFormBuilder.generateForm(Template, Class, Map, String)method.replaceField(Template template, String templateFieldName, Class propertyType, String name, String[] values, String prefix) Generates a form field for one particular property name and always replace the content of the template values that match the auto-generation name format.replaceField(Template template, String templateFieldName, Class propertyType, ConstrainedProperty property, String[] values, String prefix) Generates a form field for one particular property and always replace the content of the template values that match the auto-generation name format.replaceField(Template template, String templateFieldName, String name, String[] values, String prefix) Generates a form field for one particular property name and always replace the content of the template values that match the auto-generation name format.replaceField(Template template, String templateFieldName, ConstrainedProperty property, String[] values, String prefix) Generates a form field for one particular property and always replace the content of the template values that match the auto-generation name format.protected abstract StringsanitizeAttributes(String value) selectParameter(Template template, String name, String[] values) Generates the required attributes so that an existing form field indicates its checked or selected status.voidunselectParameter(Template template, String name, String[] values) Removes the generated attributes that indicate that an existing form field is checked or selected
-
Constructor Details
-
AbstractFormBuilder
public AbstractFormBuilder()
-
-
Method Details
-
getIdName
-
getIdAttributes
-
getIdValue
-
getIdMinlength
-
getIdMaxlength
-
getIdRequired
-
getIdChecked
-
getIdOptions
-
getIdSelected
-
getIdLabel
-
getIdDisabled
-
getIdFormOption
-
getValueSelected
-
getValueChecked
-
getBuilderTemplateInstance
-
sanitizeAttributes
-
generateFieldHidden
-
generateFieldInput
-
generateFieldSecret
-
generateFieldTextarea
-
generateFieldRadio
-
generateFieldCheckbox
-
getValidationBuilder
Description copied from interface:FormBuilderReturns theValidationBuilderthat is used by thisFormBuilder.- Specified by:
getValidationBuilderin interfaceFormBuilder- Returns:
- this
FormBuilder'sValidationBuilder
-
generateForm
public Collection<String> generateForm(Template template, Class beanClass, Map<String, String[]> values, String prefix) throws BeanUtilsExceptionDescription copied from interface:FormBuilderGenerates all the form fields for a bean class.If content has already been filled in for any of the template values that are normally replaced with generated form fields, no generation will happen for those and the existing content will simply remain present.
- Specified by:
generateFormin interfaceFormBuilder- Parameters:
template- the template instance that will be used for the form generationbeanClass- the bean class whose properties will be analyzed for the form generationvalues- a map of name-value pairs that indicate the currently active context for the form that will be generated, these are typically the values that have been submitted previously through a web page. The values will be used to pre-populate the form fields with content.prefix- the prefix of the bean property names that should be used while generating the form, this is handy to use when the several forms are present that use the same bean class or that has overlapping property names- Returns:
- the collection of template value names that have been generated
- Throws:
BeanUtilsException- when errors occurred during the form generation
-
generateForm
public Collection<String> generateForm(Template template, Object bean, Map<String, String[]> values, String prefix) throws BeanUtilsExceptionDescription copied from interface:FormBuilderGenerates all the form fields for a bean instance.If content has already been filled in for any of the template values that are normally replaced with generated form fields, no generation will happen for those and the existing content will simply remain present.
- Specified by:
generateFormin interfaceFormBuilder- Parameters:
template- the template instance that will be used for the form generationbean- the bean instance whose properties and validation errors will be analyzed for the form generationvalues- a map of name-value pairs that indicate the currently active context for the form that will be generated, these are typically the values that have been submitted previously through a web page. The values will be used to pre-populate the form fields with content.prefix- the prefix of the bean property names that should be used while generating the form, this is handy to use when the several forms are present that use the same bean class or that has overlapping property names- Returns:
- the collection of template value names that have been generated
- Throws:
BeanUtilsException- when errors occurred during the form generation
-
generateForm
protected Collection<String> generateForm(Template template, Class beanClass, Object bean, Map<String, String[]> values, String prefix) throws BeanUtilsException- Throws:
BeanUtilsException
-
generateFormField
-
generateField
public Collection<String> generateField(Template template, ConstrainedProperty property, String[] values, String prefix) Description copied from interface:FormBuilderGenerates a form field for one particular property.If content has already been filled in for any of the template values that are normally replaced with generated form fields, no generation will happen for those and the existing content will simply remain present.
- Specified by:
generateFieldin interfaceFormBuilder- Parameters:
template- the template instance that will be used for the form generationproperty- the constrained property that the form field will be generated forvalues- the current values of the property, these are typically the values that have been submitted previously through a web page. The values will be used to pre-populate the form field with content.prefix- the prefix of the bean property names that should be used while generating the form, this is handy to use when the several forms are present that use the same bean class or that has overlapping property names- Returns:
- the collection of template value names that have been generated
-
generateField
public Collection<String> generateField(Template template, Class propertyType, ConstrainedProperty property, String[] values, String prefix) Description copied from interface:FormBuilderGenerates a form field for one particular property.If content has already been filled in for any of the template values that are normally replaced with generated form fields, no generation will happen for those and the existing content will simply remain present.
- Specified by:
generateFieldin interfaceFormBuilder- Parameters:
template- the template instance that will be used for the form generationpropertyType- the type of the propertyproperty- the constrained property that the form field will be generated forvalues- the current values of the property, these are typically the values that have been submitted previously through a web page. The values will be used to pre-populate the form field with content.prefix- the prefix of the bean property names that should be used while generating the form, this is handy to use when the several forms are present that use the same bean class or that has overlapping property names- Returns:
- the collection of template value names that have been generated
-
replaceField
public Collection<String> replaceField(Template template, String templateFieldName, ConstrainedProperty property, String[] values, String prefix) Description copied from interface:FormBuilderGenerates a form field for one particular property and always replace the content of the template values that match the auto-generation name format.This method also adds a
templateFieldNameparameter. It allows you to use another property name for the template values than the one of the actual bean property. You will typically use this when you dynamically generate a form and iterate over the generation of certain fields. So, for example, when you have properties namedanswer1andanswer2, you can use this template snippet:<!--v answers/--> <!--b answer--> <!--v form:input:answer/--> <!--/b-->
By using thereplaceField(template, "answer", property, null, null)method call for each answer property and appending theanswerblock to theanswersvalue, you can benefit from the automatic form field generation but still dynamically aggregate the results into one area.- Specified by:
replaceFieldin interfaceFormBuilder- Parameters:
template- the template instance that will be used for the form generationtemplateFieldName- the name of the form field that will be used to look for supported value tags in the property templateproperty- the constrained property that the form field will be generated forvalues- the current values of the property, these are typically the values that have been submitted previously through a web page. The values will be used to pre-populate the form field with content.prefix- the prefix of the bean property names that should be used while generating the form, this is handy to use when the several forms are present that use the same bean class or that has overlapping property names- Returns:
- the collection of template value names that have been generated
-
replaceField
public Collection<String> replaceField(Template template, String templateFieldName, Class propertyType, ConstrainedProperty property, String[] values, String prefix) Description copied from interface:FormBuilderGenerates a form field for one particular property and always replace the content of the template values that match the auto-generation name format.The documentation of the
previous replaceField methodcontains more information about the functionality of this method.- Specified by:
replaceFieldin interfaceFormBuilder- Parameters:
template- the template instance that will be used for the form generationtemplateFieldName- the name of the form field that will be used to look for supported value tags in the property templatepropertyType- the type of the propertyproperty- the constrained property that the form field will be generated forvalues- the current values of the property, these are typically the values that have been submitted previously through a web page. The values will be used to pre-populate the form field with content.prefix- the prefix of the bean property names that should be used while generating the form, this is handy to use when the several forms are present that use the same bean class or that has overlapping property names- Returns:
- the collection of template value names that have been generated
-
generateField
protected Collection<String> generateField(Template template, String templateFieldName, Class propertyType, ConstrainedProperty property, String[] values, String prefix, ArrayList<String> setValues, boolean replaceExistingValues) -
generateField
public Collection<String> generateField(Template template, String name, String[] values, String prefix) Description copied from interface:FormBuilderGenerates a form field for one particular property name.If content has already been filled in for any of the template values that are normally replaced with generated form fields, no generation will happen for those and the existing content will simply remain present.
- Specified by:
generateFieldin interfaceFormBuilder- Parameters:
template- the template instance that will be used for the form generationname- the name of the property that the form field will be generated forvalues- the current values of the property, these are typically the values that have been submitted previously through a web page. The values will be used to pre-populate the form field with content.prefix- the prefix of the bean property names that should be used while generating the form, this is handy to use when the several forms are present that use the same bean class or that has overlapping property names- Returns:
- the collection of template value names that have been generated
-
generateField
public Collection<String> generateField(Template template, Class propertyType, String name, String[] values, String prefix) Description copied from interface:FormBuilderGenerates a form field for one particular property name.If content has already been filled in for any of the template values that are normally replaced with generated form fields, no generation will happen for those and the existing content will simply remain present.
- Specified by:
generateFieldin interfaceFormBuilder- Parameters:
template- the template instance that will be used for the form generationpropertyType- the type of the propertyname- the name of the property that the form field will be generated forvalues- the current values of the property, these are typically the values that have been submitted previously through a web page. The values will be used to pre-populate the form field with content.prefix- the prefix of the bean property names that should be used while generating the form, this is handy to use when the several forms are present that use the same bean class or that has overlapping property names- Returns:
- the collection of template value names that have been generated
-
replaceField
public Collection<String> replaceField(Template template, String templateFieldName, String name, String[] values, String prefix) Description copied from interface:FormBuilderGenerates a form field for one particular property name and always replace the content of the template values that match the auto-generation name format.The documentation of the
previous replaceField methodcontains more information about the functionality of this method.- Specified by:
replaceFieldin interfaceFormBuilder- Parameters:
template- the template instance that will be used for the form generationtemplateFieldName- the name of the form field that will be used to look for supported value tags in the property templatename- the name of the property that the form field will be generated forvalues- the current values of the property, these are typically the values that have been submitted previously through a web page. The values will be used to pre-populate the form field with content.prefix- the prefix of the bean property names that should be used while generating the form, this is handy to use when the several forms are present that use the same bean class or that has overlapping property names- Returns:
- the collection of template value names that have been generated
- See Also:
-
replaceField
public Collection<String> replaceField(Template template, String templateFieldName, Class propertyType, String name, String[] values, String prefix) Description copied from interface:FormBuilderGenerates a form field for one particular property name and always replace the content of the template values that match the auto-generation name format.The documentation of the
previous replaceField methodcontains more information about the functionality of this method.- Specified by:
replaceFieldin interfaceFormBuilder- Parameters:
template- the template instance that will be used for the form generationtemplateFieldName- the name of the form field that will be used to look for supported value tags in the property templatepropertyType- the type of the propertyname- the name of the property that the form field will be generated forvalues- the current values of the property, these are typically the values that have been submitted previously through a web page. The values will be used to pre-populate the form field with content.prefix- the prefix of the bean property names that should be used while generating the form, this is handy to use when the several forms are present that use the same bean class or that has overlapping property names- Returns:
- the collection of template value names that have been generated
- See Also:
-
generateField
-
generateField
-
generateFieldText
protected void generateFieldText(String prefix, boolean setValue, boolean valueAsAttribute, boolean limitLength, boolean disableField, boolean requireField, Template template, String templateFieldName, String name, ConstrainedProperty property, String[] values, Template builderTemplate, List<String> setValues, boolean replaceExistingValues) -
generateFieldCollection
-
generateFieldSelect
-
generateFieldDisplay
-
generateLabel
protected String generateLabel(Template template, String templateFieldName, String value) throws TemplateException - Throws:
TemplateException
-
removeForm
Description copied from interface:FormBuilderRemoves the content of all the template values that would otherwise be filled in with generated form fields through theFormBuilder.generateForm(Template, Class, Map, String)method.- Specified by:
removeFormin interfaceFormBuilder- Parameters:
template- the template instance whose values will be clearedbeanClass- the bean class whose properties will be analyzed for clearing the form field valuesprefix- the prefix of the bean property names that should be used while clearing the form, this is handy to use when the several forms are present that use the same bean class or that has overlapping property names- Throws:
BeanUtilsException- when errors occurred during the clearing of the form- See Also:
-
removeField
Description copied from interface:FormBuilderRemoves the content of the template value that would otherwise be filled in with a generated form field through aFormBuilder.generateField(rife.template.Template, rife.validation.ConstrainedProperty, java.lang.String[], java.lang.String)method.- Specified by:
removeFieldin interfaceFormBuilder- Parameters:
template- the template instance whose values will be clearedname- the name of the property for which the template value will be clearedprefix- the prefix of the bean property names that should be used while clearing the form, this is handy to use when the several forms are present that use the same bean class or that has overlapping property names- See Also:
-
removeField
Description copied from interface:FormBuilderRemoves the content of the template value that would otherwise be filled in with a generated form field through aFormBuilder.replaceField(rife.template.Template, java.lang.String, rife.validation.ConstrainedProperty, java.lang.String[], java.lang.String)method.- Specified by:
removeFieldin interfaceFormBuilder- Parameters:
template- the template instance whose values will be clearedtemplateFieldName- the that is use in the template values to identify the property that has to be cleared- See Also:
-
selectParameter
Description copied from interface:FormBuilderGenerates the required attributes so that an existing form field indicates its checked or selected status.This method will check the template for certain value tags and set them to the correct attributes according to the name and the provided values in this method. This is dependent on the template type and currently only makes sense for
htmltemplates.For example for select boxes, consider the name '
colors', the values 'blue' and 'red', and the following HTML template excerpt:<select name="colors"> <option value="blue"{{v colors:blue:selected}}{{/v}}>Blue</option> <option value="orange"{{v colors:orange:selected}}{{/v}}>Orange</option> <option value="red"{{v colors:red:selected}}{{/v}}>Red</option> <option value="green"{{v colors:green:selected'}}{{/v}}>Green</option> </select>the result will then be:
<select name="colors"> <option value="blue" selected="selected">Blue</option> <option value="orange">Orange</option> <option value="red" selected="selected">Red</option> <option value="green">Green</option> </select>
For example for radio buttons, consider the name '
size', the value 'large' and the following HTML template excerpt:<input type="radio" name="size" value="large"{{v size:large:checked}}{{/v}} /> <input type="radio" name="size" value="small"{{v size:small:checked}}{{/v}} />the result will then be:
<input type="radio" name="size" value="large" checked="checked" /> <input type="radio" name="size" value="small" />
For example for checkboxes, consider the name '
active', the value 'true' and the following HTML template excerpt:<input type="checkbox" name="active"{{v active:checked}}{{/v}} /> <input type="checkbox" name="senditnow"{{v senditnow:checked}}{{/v}} />the result will then be:
<input type="checkbox" name="active" checked="checked" /> <input type="checkbox" name="senditnow" />
- Specified by:
selectParameterin interfaceFormBuilder- Parameters:
template- the template instance that will be used for the generationname- the name of the parametervalues- the values of the parameter- Returns:
- the collection of template value names that have been generated
-
unselectParameter
Description copied from interface:FormBuilderRemoves the generated attributes that indicate that an existing form field is checked or selected- Specified by:
unselectParameterin interfaceFormBuilder- Parameters:
template- the template instance that will be used for the clearingname- the name of the parametervalues- the values of the parameter
-
clone
- Specified by:
clonein interfaceFormBuilder- Overrides:
clonein classObject
-