Startseite / Plugin-Entwicklung / Universelle Erweiterungen / Eingabekomponenten / GOM-Formularelement / XML-Tag-Attribute
XML Tag Attributes
Above and beyond the XML tag attributes already specified by AbstractGomFormElement, a GOM form element class may specify additional attributes by implementing method pairs that each include one getter method and one setter method for their respective attribute value. The names of these methods always follow the same pattern:
- get + attribute name (first letter capitalized, the remaining letters' capitalization is preserved)
- set + attribute name (first letter capitalized, the remaining letters' capitalization is preserved)
Getter Method Annotations
The getter method must be annotated with @GomDoc, which provides information about the purpose and availability of the attribute.
This annotation as well as optional other annotations are described below:
Annotation | Usage | Notes |
---|---|---|
@GomDoc | @GomDoc(description="<text>", since="<version>") | Mandatory annotation on all getter methods which are intended to be represented by GOM element attributes. |
@Default | @Default("<value>") | Only used for documentation. |
@InheritAnnotations | @InheritAnnotations | The superclass' or interface's method must possess explicit annotations or inherit annotations from another source. |
Example
For example, in order to specify an attribute forceUppercase, implement the methods getForceUppercase() (including @GomDoc annotation) and setForceUppercase(...). Note the CamelCase notation of the attribute name, with its first letter capitalized, while the remaining letters' capitalization is preserved.
...
private YesNo _forceUppercase = YesNo.NO;
@GomDoc(description="Convert all input to UPPERCASE", since="1.47")
@Default("no")
public YesNo getForceUppercase() {
return _forceUppercase;
}
public void setForceUppercase(final YesNo forceUppercase) {
_forceUppercase = forceUppercase;
}
....
Supplying these methods will cause FirstSpirit to accept an attribute forceUppercase in the input component's XML tag:
<CMS_MODULE>
<CUSTOM_INPUT_COMPONENT name="myCustomInputComponent" forceUppercase="no">
<LANGINFOS>
<LANGINFO lang="*" label="Custom InputComponent" />
</LANGINFOS>
</CUSTOM_INPUT_COMPONENT>
</CMS_MODULE>
The above code example showing getter and setter methods assume that the YesNo objects these methods operate on are never null. This results in the attribute always being added to a GOM form definition upon code completion or save, even if it has not been explicitly specified. If the attribute should be made truly optional (i.e., not appear in a GOM form definition unless explicitly specified), the getter method as well as the YesNo parameter of the setter method should be annoted as nullable (e.g. @Nullable), and the field (in the example, _forceUppercase) should not be initialized with a default value. |