Summary:
setting panels content is optional and
params can always be
null - setXyzKey(String i18nKey, String[] params)
- setErrorComponent(FormItem quickFixWizard)
accessing different panels within velocity of a form item:
- $r.render("formElementName_LABEL")
- $r.render("formElementName_ERROR")
- $r.render("formElementName_EXAMPLE")
find out about
form item attributes by querying it from the velocity page with:
- $f.isMandatory("formElementName")
- $f.hasError("formElementName")
- $f.hasExample("formElementName")
- $f.hasLabel("formElementName")
whereas
$f. is the {@link FormDecorator} instance in the velocity.
Description:
Each implemented form item consists of 4 panels appearing as div's in the html rendered page. They belong together in a
logical way, but are
layoutable, e.g. placeable anywhere within a velocity page. The following figure illustrates the logical composition.
- the Element panel
The form element panel holds for example one or more checkboxes, a dropdownbox, an input field, ... any other html form element, a link!, a custom element! - the Label panel
textlabel for the element - the Error panel
Either a textlabel as error text or another form element. This form element can then start a subworkflow explaining the error or for fixing the error. - the Example panel
example text, explaing an input format or how to proceed with the shown element.
The following figure shows a concrete example of a yes-no switch, the form element is labeled "Depending on date". The screenshot is taken in
debug mode mini which is available in development mode only. SingleSelectionImpl is the FormItem implemenation in this case.
The java code to create the above yes-no-switch looks as follows. Please note the anonymous class creation style, with a initializer block. This helps grouping the code:
- 519: dateSwitch is the name of the element in the velocity container
- 521/522: form.easy.dateSwitch is the i18n key for labeling, and the label is made visible.
- 523/524: sets the i18n keys for yes and no, and selects no as default
- 528: add an onclick listener, so you get informed if yes or no is clicked
- 529: final step of adding the form element to form (layout), it is then available in the velocity page layouting the form under the name dateSwitch
The form item goes to a velocity page under defined name, e.g. dateSwitch, and the corresponding logical panels are accessed with the following convention:
- form element name_LABEL
- form element name_ERROR
- form element name_EXAMPLE
It is very common that a layout needs information about whether a form item has an error, example, label or is mandatory. This information is available through a {@link org.olat.core.gui.components.form.flexible.FormDecorator}which can be accessed for example as
$f.hasError("dateSwitch").
The {@link FormItem} is aggregated within {@link FormItemContainer} and bothtogether form the composite pattern.
They play together with the {@link Component} and {@link Container}
Initial Date: 24.11.2006
@author patrickb