Class WindowControllerTag
- 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.window.tags.WindowControllerTag
-
- All Implemented Interfaces:
ConditionalTag
,PropertySupport
,org.apache.commons.jelly.DynaTag
,org.apache.commons.jelly.impl.BeanSource
,org.apache.commons.jelly.Tag
- Direct Known Subclasses:
FormControllerTag
public class WindowControllerTag extends UseBeanBaseTag
A tag handler class that allows the creation of window controllers.
A window controller is an object that is associated with a window. It will typically handle events triggered by the window or its components and thus implement logic. A standard use case would be a controller that performs validation of user input and allows closing a dialog only if all input fields contain valid data.
With this tag such controller objects can be automatically created and initialized with data related to the window and the whole builder process. As an alternative it is also possible to create a controller object manually and initialize it after the builder process has been completed.
This tag is derived from
UseBeanBaseTag
and thus provides advanced functionality for creating a bean instance of an arbitrary class and initializing its properties. Especially the full power of the dependency injection framework can be used for constructing controller beans. Bean definitions for controller beans per default have access to a bunch of objects that may be of interest for such a controller, e.g. the current window, the form object, the created GUI controls, or the defined action objects. The Javadocs for the classesComponentBuilderData
,ActionBuilder
, andWindowBuilderData
describe all objects that can be accessed in the current bean context.An example of using this tag could look as follows:
<!-- Define the bean for the controller --> <di:bean name="CTRL_WINDOW" singleton="false" beanClass="com.mypackage.WindowController"> <di:setProperty property="window" refName="CURRENT_WINDOW"/> </di:bean> <!-- The frame definition including the controller --> <w:frame title="Testwindow"> <!-- Define the GUI here --> ... <w:controller beanName="CTRL_WINDOW"/> </w:frame>
After the controller bean has been created and initialized it is checked whether it implements certain interfaces:
- If it implements the
WindowListener
interface, it will be registered as a window listener at the newly created window. - If it implements the
WindowClosingStrategy
interface, it will be set as the new window's closing strategy.
- Version:
- $Id: WindowControllerTag.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
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 WindowControllerTag()
Creates a new instance ofWindowControllerTag
.WindowControllerTag(Class<?> defaultClass, Class<?> baseClass)
Creates a new instance ofWindowControllerTag
and allows setting a default bean class and a base class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Window
fetchWindow()
Obtains the window for this controller.protected boolean
passResults(Object bean)
Processes and initializes the controller bean and passes it to an enclosing window tag.protected void
registerController(Object controller, Window window)
Checks the interfaces implemented by the controller bean and performs necessary registrations.-
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
-
-
-
-
Constructor Detail
-
WindowControllerTag
public WindowControllerTag()
Creates a new instance ofWindowControllerTag
.
-
WindowControllerTag
public WindowControllerTag(Class<?> defaultClass, Class<?> baseClass)
Creates a new instance ofWindowControllerTag
and allows setting a default bean class and a base class. The default class is used when no bean class is specified. If a base class is set, the tag checks whether the bean is of this class or a derived class.- Parameters:
defaultClass
- the default classbaseClass
- the base class
-
-
Method Detail
-
passResults
protected boolean passResults(Object bean) throws org.apache.commons.jelly.JellyTagException
Processes and initializes the controller bean and passes it to an enclosing window tag. Here dependency injection is prepared and performed, and the controller tag is further processed if necessary.- Overrides:
passResults
in classUseBeanBaseTag
- Parameters:
bean
- the controller bean to initialize- Returns:
- a flag whether the bean could be passed to a target
- Throws:
org.apache.commons.jelly.JellyTagException
- if an error occurs
-
registerController
protected void registerController(Object controller, Window window) throws org.apache.commons.jelly.JellyTagException
Checks the interfaces implemented by the controller bean and performs necessary registrations.- Parameters:
controller
- the controller beanwindow
- the controller's window- Throws:
org.apache.commons.jelly.JellyTagException
- if an error occurs
-
fetchWindow
protected Window fetchWindow() throws org.apache.commons.jelly.JellyTagException
Obtains the window for this controller. This implementation checks if the tag is nested inside a window tag. If this is the case, the window is obtained from this tag. Otherwise it is tried to fetch the window from the window builder data object. If this fails, too, an exception will be thrown.- Returns:
- the window for this controller
- Throws:
org.apache.commons.jelly.JellyTagException
- if the window cannot be obtained
-
-