Class InputComponentTag
- java.lang.Object
-
- org.apache.commons.jelly.TagSupport
-
- net.sf.jguiraffe.gui.builder.components.tags.FormBaseTag
-
- net.sf.jguiraffe.gui.builder.components.tags.ComponentBaseTag
-
- net.sf.jguiraffe.gui.builder.components.tags.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
tag. If one is found, the component's name will be added to the corresponding group.ComponentGroup
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 Summary
Constructors Constructor Description InputComponentTag()
Creates a new instance ofInputComponentTag
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addToGroups(String groupNames)
Adds this component's name to all groups in the given list.protected void
checkName()
Checks whether thename
attribute is set.protected abstract ComponentHandler<?>
createComponentHandler(ComponentManager manager, boolean create)
Creates the component handler used by this input component.protected FieldHandler
createFieldHandler(ComponentHandler<?> componentHandler)
Creates a field handler object for the input component.Object
getComponent()
Returns the component managed by this tag.ComponentHandler<?>
getComponentHandler()
Returns the component handler that was created by this tag.Class<?>
getComponentType()
Returns the type of the field handler that is associated with this component.String
getDisplayName()
Returns the display name of this input component.ValidatorWrapper
getFieldValidator()
Returns the field level validator.ValidatorWrapper
getFormValidator()
Returns the form level validator.String
getGroups()
Returns a comma separated list of names of the component groups this component should be added to.String
getPropertyName()
Returns the name of the associated property in the form bean.TransformerWrapper
getReadTransformer()
Returns the read transformer.String
getTypeName()
Returns the name of the type used by the field handler.TransformerWrapper
getWriteTransformer()
Returns the write transformer.protected void
handleGroups()
Handles the assignment of this component to component groups.protected void
insertField(FieldHandler fieldHandler)
Stores a newly created field handler in the central builder data object.boolean
isNoField()
Returns a flag whether for this input component no field handler should be created.protected void
process()
Executes this tag.protected void
processBeforeBody()
Performs steps before evaluation of this tag's body.void
setComponentType(Class<?> type)
Allows to explicitly set the type of the corresponding field handler object.void
setDisplayName(String s)
Set method of the displayName attribute.void
setDisplayNamegrp(String s)
Set method of the displayNamegrp attribute.void
setDisplayNameres(String s)
Set method of the displayNameres attribute.void
setFieldValidator(ValidatorWrapper fieldValidator)
Sets the field level validator.void
setFormValidator(ValidatorWrapper formValidator)
Sets the form level validator.void
setGroups(String groups)
Setter method of the groups attribute.void
setNoField(boolean noField)
Setter method for the no field attribute.void
setPropertyName(String propertyName)
Setter method for the propertyName attribute.void
setReadTransformer(TransformerWrapper readTransformer)
Sets the read transformer.void
setTypeName(String typeName)
Setter method for the typeName attribute.void
setWriteTransformer(TransformerWrapper writeTransformer)
Sets the write transformer.-
Methods inherited from class net.sf.jguiraffe.gui.builder.components.tags.ComponentBaseTag
getBackColor, getBackgroundColor, getConstraints, getFont, getFontRef, getForeColor, getForegroundColor, getName, getToolTipData, insertComponent, setBackColor, setConstraints, setFont, setFontRef, setForeColor, setName, setTooltip, setTooltipres, setTooltipresgrp
-
Methods inherited from class net.sf.jguiraffe.gui.builder.components.tags.FormBaseTag
canProcess, canProcess, convertToClass, convertToNumberWithUnit, convertToNumberWithUnit, doTag, findContainer, getBuilderData, getBuilderData, getIfName, getResourceText, getResourceText, getUnlessName, setIfName, setUnlessName
-
Methods inherited from class org.apache.commons.jelly.TagSupport
findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, getBody, getBodyText, getBodyText, getContext, getParent, invokeBody, isEscapeText, isTrim, setBody, setContext, setEscapeText, setParent, setTrim, trimBody
-
-
-
-
Method Detail
-
getComponentHandler
public ComponentHandler<?> getComponentHandler()
Returns the component handler that was created by this tag. Note that depending on the implementation of theComponentManager
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 theComponentHandler
. If noComponentHandler
has been created yet, null is returned.- Specified by:
getComponent
in classComponentBaseTag
- 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 thename
attribute is set. If this is not the case, an exception is thrown. This method is called byprocess()
. If derived classes need to check the existence of aname
attribute at an earlier point of time, they can use this method.- Throws:
org.apache.commons.jelly.MissingAttributeException
- if noname
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 callscreateComponentHandler()
for the first time.- Overrides:
processBeforeBody
in classFormBaseTag
- Throws:
org.apache.commons.jelly.JellyTagException
- if the tag is incorrectly usedFormBuilderException
- 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 classComponentBaseTag
- Throws:
FormBuilderException
- if an error occursorg.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 thegroups
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 thecreate
argument, and once after body evaluation with an argument value of false .- Parameters:
manager
- the component managercreate
- the create flag- Returns:
- the new component handler
- Throws:
FormBuilderException
- if an error occursorg.apache.commons.jelly.JellyTagException
- if a Jelly-related error occurs, e.g. the tag is incorrectly used or required attributes are missing
-
-