Class ComponentHandlerTag
- java.lang.Object
-
- org.apache.commons.jelly.TagSupport
-
- org.apache.commons.jelly.DynaTagSupport
-
- org.apache.commons.jelly.MapTagSupport
-
- org.apache.commons.jelly.tags.core.UseBeanTag
-
- net.sf.jguiraffe.gui.builder.components.tags.UseBeanBaseTag
-
- net.sf.jguiraffe.gui.builder.components.tags.ComponentHandlerTag
-
- All Implemented Interfaces:
ConditionalTag
,PropertySupport
,org.apache.commons.jelly.DynaTag
,org.apache.commons.jelly.impl.BeanSource
,org.apache.commons.jelly.Tag
public class ComponentHandlerTag extends UseBeanBaseTag
A tag handler class that allows constructing custom
ComponentHandler
objects.This tag can be placed in the body of a
FieldTag
to define theComponentHandler
that should be used by the input component to be constructed. The class of the new component handler must be specified in theclass
attribute. An instance of this class is created, initialized (which can be done by using other attributes representing properties of the newly created object), and finally passed to the enclosingFieldTag
instance. This tag will then construct a suitableFieldHandler
object and ensure that the represented component is added to the currentForm
object and to the enclosing GUI container element.With this tag handler class two common use cases can be addressed:
- Components not supported by the form builder library (e.g. custom
controls) can be added to both the resulting
Form
object and the generated GUI. For this purpose a suitable implementation of theComponentHandler
interface must be provided, which wraps the component to be added. The name of the implementation class must then be specified as the value of this tag'sclass
attribute. - Sometimes the default data provided by the supported GUI components is
not sufficient. A typical example is a group of radio buttons: Each radio
button has a boolean data object that tells whether this button is the
selected one. Instead of storing a boolean value for each radio button that
belongs to the group in the form's bean it is probably better to use a
different storage format, e.g. storing only the index of the selected button
as an int or using some kind of mapping to other values. This can be achieved
by first defining the components that should be manipulated (in this example
the radio buttons) in the usual way in the Jelly script, but setting their
noField
attribute to true. This ensures that they are not added as concrete data fields to the constructedForm
object. Then an implementation of theCompositeComponentHandler
interface must be created and specified in this tag'sclass
attribute. In this tag's body an arbitrary number ofReferenceTag
elements can be placed defining the components that should be wrapped by the new composite component handler. The components specified this way will be retrieved and added to the composite component handler. Then this composite handler will be added to theForm
object as a complex data member. It can then perform an arbitrary transformation from the containing components' native data format to another format.
This tag of course supports all attributes already defined in its base class. If references are used to define components that are to be added to a composite component handler, these references are resolved at the very end of the builder process, thus ensuring that the referred components have already been created.
- Version:
- $Id: ComponentHandlerTag.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
- See Also:
ReferenceTag
-
-
Field Summary
-
Fields inherited from class net.sf.jguiraffe.gui.builder.components.tags.UseBeanBaseTag
ATTR_BEAN_CLASS, ATTR_BEAN_NAME, ATTR_CLASS, ATTR_IF_NAME, ATTR_REF, ATTR_UNLESS_NAME, ATTR_VAR
-
-
Constructor Summary
Constructors Constructor Description ComponentHandlerTag()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addComponentReference(String ref)
Adds a reference to another component to this tag.protected static <S> void
addComponentToCompositeHandler(ComponentBuilderData builderData, CompositeComponentHandler<?,S> handler, String compName)
Helper method for adding theComponentHandler
of a component to aCompositeComponentHandler
.void
addGroupReference(String ref)
Adds a reference to a component group to this tag.protected static void
addGroupToCompositeHandler(ComponentBuilderData builderData, CompositeComponentHandler<?,?> handler, ComponentGroup group)
Helper method for adding theComponentHandler
objects for all components in the specified group to aCompositeComponentHandler
.protected void
addReference(net.sf.jguiraffe.gui.builder.components.tags.ComponentHandlerTag.Reference ref)
Adds a reference to the internal list.protected boolean
passResults(Object bean)
Passes the results of this tag to its target tag.-
Methods inherited from class net.sf.jguiraffe.gui.builder.components.tags.UseBeanBaseTag
addIgnoreProperties, doTag, fetchBean, getAdditionalProperties, getAttributeStr, getBaseClass, getIfName, getUnlessName, isOptional, processBean, setBaseClass, setProperty, useExistingBean
-
Methods inherited from class org.apache.commons.jelly.tags.core.UseBeanTag
addIgnoreProperty, convertToClass, getBean, getDefaultClass, getIgnorePropertySet, isIgnoreUnknownProperties, loadClass, newInstance, setBean, setBeanProperties, setIgnoreUnknownProperties, validateBeanProperties
-
Methods inherited from class org.apache.commons.jelly.MapTagSupport
createAttributes, getAttributes, setAttribute
-
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
-
addComponentReference
public void addComponentReference(String ref)
Adds a reference to another component to this tag. The reference will be resolved, and the corresponding component handler will be added to the newly created component handler (which must be a composite handler).- Parameters:
ref
- the name of the referenced component
-
addGroupReference
public void addGroupReference(String ref)
Adds a reference to a component group to this tag. The component handlers of all components contained in this group will be fetched and added to the newly created component handler (which must be a composite handler).- Parameters:
ref
- the name of the referenced group
-
addReference
protected void addReference(net.sf.jguiraffe.gui.builder.components.tags.ComponentHandlerTag.Reference ref)
Adds a reference to the internal list.- Parameters:
ref
- the new reference
-
passResults
protected boolean passResults(Object bean) throws org.apache.commons.jelly.JellyTagException
Passes the results of this tag to its target tag. This implementation checks whether the parent tag of this tag is of typeFieldTag
. If this is the case, the newly created bean instance is added as a component handler. If references to other components or groups are defined, the corresponding reference objects are scheduled for resolving (the new bean must then implement theCompositeComponentHandler
interface).- Overrides:
passResults
in classUseBeanBaseTag
- Parameters:
bean
- the newly created bean- Returns:
- a flag whether the bean could be passed to the target
- Throws:
org.apache.commons.jelly.JellyTagException
- if an error occurs
-
addComponentToCompositeHandler
protected static <S> void addComponentToCompositeHandler(ComponentBuilderData builderData, CompositeComponentHandler<?,S> handler, String compName) throws FormBuilderException
Helper method for adding theComponentHandler
of a component to aCompositeComponentHandler
. This method tries to obtain the component handler for the component with the specified name from the builder data object. Then it adds this handler to the complex handler. Note that it cannot be verified that the childComponentHandler
is actually of the expected data type. Therefore it is not possible to exclude that aClassCastException
might be thrown.- Type Parameters:
S
- the type of the childComponentHandler
- Parameters:
builderData
- the builder data objecthandler
- theCompositeComponentHandler
compName
- the name of the component to add- Throws:
FormBuilderException
- if the component cannot be found
-
addGroupToCompositeHandler
protected static void addGroupToCompositeHandler(ComponentBuilderData builderData, CompositeComponentHandler<?,?> handler, ComponentGroup group) throws FormBuilderException
Helper method for adding theComponentHandler
objects for all components in the specified group to aCompositeComponentHandler
. This method iterates over all components in the specified group and calls#addComponentToCompositeHandler()
for each.- Parameters:
builderData
- the builder data objecthandler
- theCompositeComponentHandler
group
- theComponentGroup
- Throws:
FormBuilderException
- if a component cannot be resolved
-
-