Class 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 classes ComponentBuilderData, ActionBuilder, and WindowBuilderData 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
    • Constructor Detail

      • WindowControllerTag

        public WindowControllerTag()
        Creates a new instance of WindowControllerTag.
      • WindowControllerTag

        public WindowControllerTag​(Class<?> defaultClass,
                                   Class<?> baseClass)
        Creates a new instance of WindowControllerTag 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 class
        baseClass - 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 class UseBeanBaseTag
        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 bean
        window - 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