Effectively Implementing Appcelerator RIAs and Services
Purpose
If you are venturing to implement a Rich Internet Application (RIA) with Appcelerator, then there are features about the framework that I’m really geared up about that help you implement your solution effectively. When used together these items enable the agile creation of solutions in a shorter time that integrate nicely with services in an existing architecture and provide a richer user experience for clients.
Achieving Re-use
There are a bunch of ways to do this, personally I leverage app:content files judiciously. You can provide args in the definition of your content files so that you can use the same content file over again. Some things to keep in mind:
- reference the args as #{argname} in your element ids, any variables, and make sure that functions you call take this into account (possibly make them stateless)
- the order in which the content file is loaded to make sure that listeners are properly setup to respond to messages
here is an example app:content reference
1 2 3 | <app:content lazy="false" on="mainstate[person] then show else hide" args="{'prefix':'person'}"> </app:content> |
here is the content.html file
1 2 | <div id="#{prefix}header" ... </div> |
I know that this may be abstract, but the point is that you can use the arg “prefix” to reuse the file and provide alternative behavior based on it.
Mocking Services
You can mock out server side services extremely easily with the framework. This is extremely useful whether your goal is:
- Visual Use Cases: implementing a prototype that results in 100% useable application code
- Working offline: no need to run a web server at all, you can directly run off of a simple file
Once you have this in place, you have a well defined contract in place which makes knocking out the service implementation a snap.
No restart
If you are just working on your application (no service work), you can directly make changes to your application without requiring rebuilding and redeploying your application. In java I typically work directly in my tomcat deploy directory and have an ant task to pull the web files into my workspace. With our next version of the framework coming out, this will be even easier with our support for Jetty coming and the Ruby based command line tool. In the meantime, the following is useful in your java project:
1 | ant pullweb |
Make sure that you have your deploy.dir setup in your $HOME/.ant.properties for example:
1 | deploy.dir=/Applications/apache-tomcat-6.0.14/webapps |
With our Ruby implementation for example, this is even easier (running webbrick directly in your workspace).
Great Support for Model Objects
I’ve touched a bit on this in a previous post on JSON serialization with Appcelerator java services. To summarize the framework enables
- Hibernate persistence: ModelObjects can easily be used with our Hibernate integration
- JSON serialization: Serializing and deserialing complex objects is a snap
Slick support for forms
In case you haven’t looked, you dont need to include a form tag anywhere in the application: simply add a fieldset attribute to your input elements and put something like this
1 2 3 4 | <input name="age" fieldset="save_person" type="text"/> <input name="name" fieldset="save_person" type="text"/> <input value="Create Person" fieldset="save_person"/> on="click then r:create.person.request" type="button"/> |
This will create a message of type r:create.person.request with the payload being all your input elements with fieldset of “save_person” ex:
1 | {'name':'jim','age':'35'} |
To me, this is very eloquent solution to leveraging form input elements with a messaging architecture.
Easy to use UI widgets
I love some of the widgets that are at your fingertips. Some of the ones that i use the most
- app:panel: slick styling
- app:datatable: great way to show rows of data
- app:chart: fantastic visual effects to bring life to data
All these widgets have a very terse usage that is very intuitive. For example, using this set, I was able to knock out a realtime dashboard application in 3 evenings.
Service Platform Options
Pitching the right framework is something that varies from project to project. For example, possibly your client wants to leverage an existing java infrastructure and is sold on its robustness for scaling enterprise applications, while on the other side possibly you want to take advantage of using a Rails controller and ORM/Active Record implementation for rapid development. On the same level you also have the option for implementing services to customers that deliver in a .Net solution architecture. Many other platforms also exist (python, PHP) enabling the opportunity to plug into those services as well.
The app:get non-visual widget also makes pre-existing services accessible as well and since Messaging is at the heart of the implementation, plugging into an ESB or pure MOM framework is perfectly setup as well.
Wrap Up
In this article 7 key tips have been covered
- re-use
- mock services
- no restart
- model objects
- messaging & forms
- UI widgets
- platform options
Although there are more items that have not been covered here, these are the ones that appeal personally to me and have noticed a huge gain in doing much more with less effort.