A Lightning Look at Configuration
Configuring Swiz in your Flex or AIR application is very straightforward: declare Swiz
, define the beanProviders
and config
properties, and optionally define one or more loggingTargets
to view debugging messages. Here is an example:
<script src="http://gist.github.com/383055.js?file=quickswiz_main.xml"></script>
Non-visual components that you want Swiz to manage are defined in a BeanProvider
tag. Any beans that you define within the BeanProvider
are processed by Swiz for dependency injection and the creation of event mediators. In the following example, a UserService
and a UserController
are created:
<script src="http://gist.github.com/383055.js?file=quickswiz_beans.xml"></script>
The "Big Three": Dependency Injection, Event Handling, and Server Interaction
The three most commonly used features of Swiz are its dependency injection capabilities, its event handling features, and its server interaction utilities. Let's look at how each of these work.
Adding Dependency Injection
Dependencies are injected by using [Inject]
metadata. In this example, the UserService
is injected into the UserController
:
<script src="http://gist.github.com/383055.js?file=quickswiz_usercontroller.java"></script>
In addition to injecting a bean, you can inject individual bean properties. In this example, the currentUser
property of the UserController
is injected into a UserForm
visual component. Note that it is not necessary for the UserForm
to be declared as a bean in the BeanProviders
tag. When visual components are added to the display list, Swiz automatically inspects them and processes any metadata tags that are found.
<script src="http://gist.github.com/383055.js?file=quickswiz_userform.mxml"></script>
Dispatching and Handling Events
<script src="http://gist.github.com/383055.js?file=quickswiz_userform.mxml"></script>
<script src="http://gist.github.com/383055.js?file=quickswiz_userevent.java"></script>
<script src="http://gist.github.com/383055.js?file=quickswiz_usercontroller.java"></script>
Talking to the Server
<script src="http://gist.github.com/383055.js?file=quickswiz_usercontroller.java"></script>
<script src="http://gist.github.com/383055.js?file=quickswiz_userservice.java"></script>