Class InputComponentTag

  • All Implemented Interfaces:
    ConditionalTag, org.apache.commons.jelly.Tag
    Direct Known Subclasses:
    ComboBoxTag, FieldTag, ListBoxTag, ProgressBarTag, PushButtonTag, SliderTag, TabbedPaneTag, TableTag, TextAreaTag, TextFieldTag, TreeTag

    public abstract class InputComponentTag
    extends ComponentBaseTag

    A base class for tag handler classes that create input components.

    This abstract tag handler class is on top of a hierarchy of tags that generate GUI widgets that gather user input and that are maintained by the Form object created during the builder operation. It provides functionality for creating and initializing field handler objects and pass them to the central builder data object. Sub classes only have to deal with the creation of the correct component handler objects.

    This class implements support for some common attributes used by input component tags. The following table lists these attributes:

    Attribute Description Optional
    name Defines the name under which the corresponding field handler will be stored in the constructed form object. This name must be unique and is mandatory in contrast to simple components. no
    displayName This property allows to define an additional display name. The display name is the one that will be presented to the user for this input component, e.g. in validation error messages. Its definition is optional; if it is missing, the name of the input component will be used as display name. yes
    displayNameres Analog to displayName, but allows to define the display name from a resource ID. yes
    displayNamegrp If the display name is defined as a resource ID, here a special resource group can be defined. If no resource group is specified, the default resource group will be used. yes
    propertyName With this attribute the property name can be defined. This value is used to set the propertyName property of the corresponding field handler, which makes it possible to use a different name in the form bean than the internal name. yes
    typeName Allows to specify a type name for the field handler that is created for this component. This should be necessary only in very special cases. Usually the type can be determined from the component handler. yes
    noField If this boolean attribute is set to true , the newly created component handler will not be added to a field handler and stored in the form object. It will only be added to the list of component handlers in the central builder data object. This is useful for defining complex field handlers that contain other handlers, e.g. a button group whose data is determined by the data of the contained buttons. yes
    groups In this attribute a comma separated list of names of already defined component groups can be specified. This tag will then add the new component's name to each group in the list. If this attribute is undefined, the tag will look for an enclosing ComponentGroup tag. If one is found, the component's name will be added to the corresponding group. yes

    In the tag's body a couple of other tags are supported that set other properties of the input component, e.g. a font or a constraints object or validators.

    Version:
    $Id: InputComponentTag.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Constructor Detail

      • InputComponentTag

        public InputComponentTag()
        Creates a new instance of InputComponentTag.
    • Method Detail

      • getComponentHandler

        public ComponentHandler<?> getComponentHandler()
        Returns the component handler that was created by this tag. Note that depending on the implementation of the ComponentManager this value may be null before the tag's body has been completely evaluated.
        Returns:
        the created component handler
      • getComponent

        public Object getComponent()
        Returns the component managed by this tag. This implementation obtains this component from the ComponentHandler. If no ComponentHandler has been created yet, null is returned.
        Specified by:
        getComponent in class ComponentBaseTag
        Returns:
        the component managed by this tag
      • getFieldValidator

        public ValidatorWrapper getFieldValidator()
        Returns the field level validator.
        Returns:
        the field level validator
      • setFieldValidator

        public void setFieldValidator​(ValidatorWrapper fieldValidator)
        Sets the field level validator.
        Parameters:
        fieldValidator - the field level validator
      • getFormValidator

        public ValidatorWrapper getFormValidator()
        Returns the form level validator.
        Returns:
        the form level validator
      • setFormValidator

        public void setFormValidator​(ValidatorWrapper formValidator)
        Sets the form level validator.
        Parameters:
        formValidator - the form level validator
      • isNoField

        public boolean isNoField()
        Returns a flag whether for this input component no field handler should be created.
        Returns:
        the no field flag
      • setNoField

        public void setNoField​(boolean noField)
        Setter method for the no field attribute.
        Parameters:
        noField - the attribute value
      • getPropertyName

        public String getPropertyName()
        Returns the name of the associated property in the form bean.
        Returns:
        the name of the property
        See Also:
        FieldHandler.getPropertyName()
      • setPropertyName

        public void setPropertyName​(String propertyName)
        Setter method for the propertyName attribute.
        Parameters:
        propertyName - the attribute value
      • getTypeName

        public String getTypeName()
        Returns the name of the type used by the field handler.
        Returns:
        the field handler data type
      • setTypeName

        public void setTypeName​(String typeName)
        Setter method for the typeName attribute.
        Parameters:
        typeName - the attribute value
      • getGroups

        public String getGroups()
        Returns a comma separated list of names of the component groups this component should be added to.
        Returns:
        a list of group names
      • setGroups

        public void setGroups​(String groups)
        Setter method of the groups attribute.
        Parameters:
        groups - the attribute value
      • getReadTransformer

        public TransformerWrapper getReadTransformer()
        Returns the read transformer.
        Returns:
        the read transformer
      • setReadTransformer

        public void setReadTransformer​(TransformerWrapper readTransformer)
        Sets the read transformer.
        Parameters:
        readTransformer - the read transformer
      • getWriteTransformer

        public TransformerWrapper getWriteTransformer()
        Returns the write transformer.
        Returns:
        the write transformer
      • setWriteTransformer

        public void setWriteTransformer​(TransformerWrapper writeTransformer)
        Sets the write transformer.
        Parameters:
        writeTransformer - the write transformer
      • getDisplayName

        public String getDisplayName()
        Returns the display name of this input component. This name can be either directly defined or using a resource ID. If no display name is defined, null is returned.
        Returns:
        the display name for this input component
      • setDisplayName

        public void setDisplayName​(String s)
        Set method of the displayName attribute.
        Parameters:
        s - the attribute's value
      • setDisplayNameres

        public void setDisplayNameres​(String s)
        Set method of the displayNameres attribute.
        Parameters:
        s - the attribute's value
      • setDisplayNamegrp

        public void setDisplayNamegrp​(String s)
        Set method of the displayNamegrp attribute.
        Parameters:
        s - the attribute's value
      • getComponentType

        public Class<?> getComponentType()
                                  throws FormBuilderException
        Returns the type of the field handler that is associated with this component. This implementation checks whether a type name attribute was specified. If this is the case, the name is converted to a class object. Otherwise null is returned.
        Returns:
        the type of the field handler
        Throws:
        FormBuilderException - if an error occurs
      • setComponentType

        public void setComponentType​(Class<?> type)
        Allows to explicitly set the type of the corresponding field handler object. The class set here takes precedence over a typeName attribute. The method could be called by nested transformer tags.
        Parameters:
        type - the data type of this component
      • checkName

        protected void checkName()
                          throws org.apache.commons.jelly.MissingAttributeException
        Checks whether the name attribute is set. If this is not the case, an exception is thrown. This method is called by process() . If derived classes need to check the existence of a name attribute at an earlier point of time, they can use this method.
        Throws:
        org.apache.commons.jelly.MissingAttributeException - if no name attribute is specified
      • processBeforeBody

        protected void processBeforeBody()
                                  throws org.apache.commons.jelly.JellyTagException,
                                         FormBuilderException
        Performs steps before evaluation of this tag's body. This implementation calls createComponentHandler() for the first time.
        Overrides:
        processBeforeBody in class FormBaseTag
        Throws:
        org.apache.commons.jelly.JellyTagException - if the tag is incorrectly used
        FormBuilderException - if an error occurs
      • process

        protected void process()
                        throws FormBuilderException,
                               org.apache.commons.jelly.JellyTagException
        Executes this tag. This implementation performs all steps for creating an input component and storing it in the builder results. Derived classes only need to implement the real component create operation.
        Overrides:
        process in class ComponentBaseTag
        Throws:
        FormBuilderException - if an error occurs
        org.apache.commons.jelly.JellyTagException - if a Jelly related error occurs
      • createFieldHandler

        protected FieldHandler createFieldHandler​(ComponentHandler<?> componentHandler)
                                           throws FormBuilderException
        Creates a field handler object for the input component. When this method is invoked the component handler has already been created. This implementation uses the current field handler factory to create and initialize the handler object.
        Parameters:
        componentHandler - the component handler
        Returns:
        the field handler
        Throws:
        FormBuilderException - if an error occurs
      • insertField

        protected void insertField​(FieldHandler fieldHandler)
        Stores a newly created field handler in the central builder data object. This ensures that the field is also added to the form object constructed in the builder process.
        Parameters:
        fieldHandler - the field handler
      • handleGroups

        protected void handleGroups()
                             throws FormBuilderException
        Handles the assignment of this component to component groups. Evaluates the groups attribute and checks whether this tag is nested inside a group tag.
        Throws:
        FormBuilderException - if an error occurs when associating this component to a group
      • addToGroups

        protected void addToGroups​(String groupNames)
                            throws FormBuilderException
        Adds this component's name to all groups in the given list.
        Parameters:
        groupNames - a comma separated list of group names
        Throws:
        FormBuilderException - if at least one group name is invalid
      • createComponentHandler

        protected abstract ComponentHandler<?> createComponentHandler​(ComponentManager manager,
                                                                      boolean create)
                                                               throws FormBuilderException,
                                                                      org.apache.commons.jelly.JellyTagException
        Creates the component handler used by this input component. This method must be implemented by concrete sub classes to create and initialize the specific component. It is called twice during execution of this tag: Once before evaluation of the tag's body with a value of true for the create argument, and once after body evaluation with an argument value of false .
        Parameters:
        manager - the component manager
        create - the create flag
        Returns:
        the new component handler
        Throws:
        FormBuilderException - if an error occurs
        org.apache.commons.jelly.JellyTagException - if a Jelly-related error occurs, e.g. the tag is incorrectly used or required attributes are missing