Class FormValidationTriggerFocus

  • All Implemented Interfaces:
    EventListener, FormEventListener, FormFocusListener, FormValidationTrigger

    public class FormValidationTriggerFocus
    extends Object
    implements FormValidationTrigger, FormFocusListener

    A specialized FormValidationTrigger implementation that triggers a validation operation whenever the user leaves an input field.

    This validation trigger implementation registers itself as focus listener on all input components of the form to monitor. Whenever it receives a focus lost event, it triggers a validation operation.

    This way the user gets fast feedback about invalid input. Invalid fields can be marked while editing the form, and fresh validation error messages can be displayed. Because validation happens only if the user switches to another input field, the number of validations (a UI updates related to validation) is limited. So this FormValidationTrigger is a good compromise between real-time validation feedback and annoying the user with permanent validation messages.

    Implementation note: This class is not thread-safe. An instance should be associated with a single FormController only and not be reused.

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

      • FormValidationTriggerFocus

        public FormValidationTriggerFocus()
    • Method Detail

      • getFormController

        public final FormController getFormController()
        Returns a reference to the associated FormController.
        Returns:
        the FormController
      • initTrigger

        public void initTrigger​(FormController controller)
        Initializes this FormValidationTrigger. This implementation stores the FormController reference and registers itself as global focus listener. Thus it can intercept every change in the focus of the associated input form.
        Specified by:
        initTrigger in interface FormValidationTrigger
        Parameters:
        controller - the FormController
      • focusGained

        public void focusGained​(FormFocusEvent e)
        Notifies this object that an input component gained focus. This implementation does nothing.
        Specified by:
        focusGained in interface FormFocusListener
        Parameters:
        e - the focus event
      • focusLost

        public void focusLost​(FormFocusEvent e)
        Notifies this object that an input component lost focus. This implementation triggers the FormController to perform another validation.
        Specified by:
        focusLost in interface FormFocusListener
        Parameters:
        e - the focus event