Welcome!

Java Authors: Walter H. Pinson, III, Maureen O'Gara, Yakov Werde, Tony Bishop, Kevin Jackson

Related Topics: Java, Adobe Flex

Java: Article

Using the J2EE View Helper Pattern in Your AIR Applications

I'm creating many small prototype applications using AIR and Flex 3

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.

More Stories By Marco Casario

Marco 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.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.