Flex News Desk
Using the J2EE View Helper Pattern in Your AIR Applications
I'm creating many small prototype applications using AIR and Flex 3
Feb. 27, 2008 09:00 AM
Marco Casario's "RIAvolutionize the Web" Blog
I'm currently creating many small applications using AIR and Flex 3. Most of them are prototypes with the purposes of showing AIR features and the quantity of code is small (600 lines at most).
In this context it does not make much sense to use a framework or architecture such as Cairngorm or PureMVC or Defraga. So that I'm using a lot what in JSP is called the View Helper pattern.
The view components of your AIR and Flex applications, that will only contain the controls that define the user interface of the application, will use a simple View Helper, consisting in an ActionScript class, to encapsulate business logic in a helper instead of a view, making our application more modular by facilitating component re-use.
A view contains formatting code, delegating its processing responsibilities to its helper classes, implemented as an Actionscript class. Helpers also store the view's intermediate data model and serve as business data adapters.
View helpers has the following advantages:
- improve the separation between the presentation and the business data actinga as intermediaries between the two
- most of the code contained in a view components is merely mxml code
- the code within the view components are more readable and a designer can browse and edit it to change the visual aspects of the application in an easy way
- it can cache lookup tables for the application
To invoke a view helper you can simply
<h:UploadHelper id="uploadHelper" xmlns:h="com.comtaste.proto.controls.*" />
and the view helper UploadHelper class is an ActionScript class where you'll encapsulate the business logic of view component :
package com.casario.proto.controls
{
import flash.events.Event;
import flash.events.IOErrorEvent;
import mx.controls.Alert;
public class MainHelper
{
protected var URLString:URLRequest =
new URLRequest("http://www.domain.com/file.jsp");
[Bindable]
private var statusStr:String = new String("");
public function MainHelper()
{
super();
}
}
}
If you want to have more details and ivestigate on this pattern you can visit the View Helper Design Pattern of J2EE.
About Marco CasarioMarco Casario is CEO of Comtaste, a company devoted to develop Rich Internet Applications on the Web and for mobile devices.
He collaborates intensively with Adobe Italy as a speaker at conferences and as a consultant for Flash, Flex, and Flash Lite.
Learn more about Marco Casario at his blog http://casario.blogs.com. In 2005, Marco has founded Comtaste, a company dedicated to exploring new frontiers in Rich Internet Applications and the convergence between the web and the world of mobile devices — MobyMobile and YouThru are representative of their recent work. He is founder of the biggest worldwide Flash Lite User Group and of www.augitaly.com, a reference point for the Italian community of Adobe users, in which he carries out the role of Channel Manager for the section dedicated to Flex.