Working with a standalone Controller
Creating a controller
Brico::Command defines a
Controller interface and provides a handy base class:
AbstractController. From this base implementation, a simple but yet powerful Controller
is available, the MapBackedController. This controller manages all the complexity of command processing
while leaving you, the developer, the task of defining the source of three sets on objects need for
command processing, mainly the commands, forms and filters (if any).
MapBackedController is an abstract class, for which you must implement three methods:
getCommandMap(): a Map which every key is a command name and each value is a Command.
getFormFactoryMap(): a Map which every key is a form name and each value is a FormFactory.
getFilterSet(): a Set of FilterInjectors.
Example:
Configuring the controller
You may configure a group of properties for your controller, taking into account that if one of
them is left, a default option would be used. This gives you the freedom of configuring what you need
instead of what the component needs. The following is a list of configurable properties of the MapBackedController
and their default values:
| Property |
Default value |
| name |
*NO DEFAULT VALUE* You should name your controllers if you intend to use
more than one in the same JVM process. |
| contextFactory |
net.sf.brico.cmd.base.DefaultContextFactory |
| responseFactory |
net.sf.brico.cmd.base.DefaultResponseFactory |
| requestHandler |
net.sf.brico.cmd.RequestHandler |
exceptionConfig exceptionConfigs |
*EMPTY* |
Using the controller
To use your newly configurated controller you need a RequestFactory that will let you
create Request instances, configure it with the desired command to be execute along
with any properties that may be used in its Form and then call the process()
method of your controller, like the following example: