Form component interceptors provide a way to intercept and add extra functionality to input components on a form.
The application context specifies the list of interceptors to attach to controls constructed by the platform. This allows for a declarative model for specifying "additional" functionality to be added to various components.
Examples are interceptors to overlay validation error images and background color changes, provide popup menus in text fields, and autocompletion (as you type) for comboboxes.
To create your own FormComponentInterceptor
, you have to provide both a FormComponentInterceptor and a
FormComponentInterceptorFactory
implementation.
public interface FormComponentInterceptor { public void processLabel(String propertyName, JComponent label); public void processComponent(String propertyName, JComponent component); }
The configuration of the interceptors in the application context is done by defining the
FormComponentInterceptorFactory
in the formComponentInterceptorFactory
method.
This is the standard configuration:
@Bean public FormComponentInterceptorFactory formComponentInterceptorFactory() { ChainedInterceptorFactory factory = new ChainedInterceptorFactory(); List<FormComponentInterceptorFactory> factories = Lists.newArrayList(); factories.add(new ColorValidationInterceptorFactory()); factories.add(new OverlayValidationInterceptorFactory()); factories.add(new ShowCaptionInStatusBarInterceptorFactory()); factories.add(new ShowDescriptionInStatusBarInterceptorFactory()); factory.setInterceptorFactories(factories); return factory; }
There are a number of built-in interceptors provided with the framework. We’ll quickly explain them.
There are a number of built-in interceptors provided with the framework. We’ll quickly explain them.
--- IMAGE ---This class has been specifically made to work with Valkyrie’s validation framework and will show the errors coming from that framework
To configure this interceptor, you need to use this interceptor factory:
new OverlayValidationInterceptorFactory()
Changes the background color of the form component when an invalid value is entered. The color of the background can be set through a property.
To configure this interceptor, you need to use this interceptor factory:
new ColorValidationInterceptorFactory()--- IMAGE ---
Adds more advanced text editing functionality to text components. It adds a popup menu with "undo/redo/cut/copy/paste/select all" items. It also adds the standard keyboard accelerators for these commands to the component.
--- IMAGE ---To configure this interceptor, you need to use this interceptor factory:
new TextComponentPopupInterceptorFactory()
Adds auto completion to a combobox.
--- IMAGE ---To configure this interceptor, you need to use this interceptor factory:
new ComboBoxAutoCompletionInterceptorFactory()
Shows an image in the top left corner of the component if the contents of the component has been changed by the user. The image also has a tooltip showing the original value. To the right of the image is a small revert button. Pushing this button restores the original value in the component
--- IMAGE ---To configure this interceptor, you need to use this interceptor factory:
new DirtyIndicatorInterceptorFactory()
Selects all the text in text fields and spinners when they receive focus.
--- IMAGE ---To configure this interceptor, you need to use this interceptor factory:
new SelectAllFormComponentInterceptorFactory()
If the text is set in a text component, the caret position is set to the end of the text. This means the beginning of the text will not be visible if the text is too long to fit in the text component.
This FormComponentInterceptor "fixes" this behavior, and sets the caret to position 0.
To configure this interceptor, you need to use this interceptor factory:
new TextCaretFormComponentInterceptorFactory()
If a form property has a caption defined in the messages.properties file it will be used as the tooltip for the form component.
To configure this interceptor, you need to use this interceptor factory:
new ToolTipInterceptorFactory()
Allows customization on how a CheckBox form property is rendered, for example whether the label needs to be shown.
To configure this interceptor, you need to use this interceptor factory:
new CheckBoxFormComponentInterceptorFactory()Shows the caption of the form component in the statusbar when the component is focused.
To configure this interceptor, you need to use this interceptor factory:
new ShowCaptionInStatusBarInterceptorFactory()
Shows the description of the form component in the statusbar when the component is focused.
To configure this interceptor, you need to use this interceptor factory:
new ShowDescriptionInStatusBarInterceptorFactory()