www.guasax.com

guasax

flexframework

Agile development for Flex & AIR components

Build RIA apps and reuse your own components with Guasax

Guasax Hello World! (step by step)

Setting up the environment

According to the programming environment, we can use both FlexBuilder 2.0.1 standalone and Eclipse WTP + Flex Builder Plugin. Personally I recommend and encourage you to use the second option. Some time ago, we published an article (in Spanish) about all you need to install it. It will be very useful for next examples and for FDS usage.

Creating the project

If you want, you can follow this tutorial downloading the source code and then importing it in your programming environment. You can download it here.. Once the project has been integrated into Flex Builder, or when creating a new project, we have to realize two things:

  1. Put the GuasaxLibrary.swc library into the flex build path.
  2. Update the compilation options to read the messages file from the appropiated directory. described also here

If we start from the above code we will have this solved, except for some absolute paths taken by FlexBuilder that can be fixed editing the project properties and updating the Flex Build path -> Library path.

Our main application file

In this example, we have the minimum number of files to carry on the hello world function. First of all, there is the main MXML file in which we declare the necessary interface code to invoke the function from a button. From the function which manages the click event we will invoke the method through guasax. Also, in the “creationComplete” application event we will initialize the framework reading our components configuration file in the container.

Here we can see the MXML code

Configuring our actions in XML

Once we know what actions we want to invoke, we have to declare them grouped in a xml file. The structure of the configuration file seems like this:

In this example we only have a component with a single action. In the component definition we also have to provide it an unique identifier and a class qualified name which is going to implement the methods that are going to be called. Inside a component we declare the actions. In this example we have a single action with an identifier equals to “sayHello” which identifies the real method name to invoke when the action is fired. In this case the identifier and the name of the action are equals but it’s not a “must”. There are a series of actions and components attributes which we will introduce you in future examples.

Creating the business logic. The BO

As we have said above, the actions are invoked in a concrete component, represented by a class called Business Object, in which we delegate operations like treatment, access and data transformation inside our application. Exactly the same from that kind of classes, we will connect with FDS if it’s necessary. So, we have in guasax a class called ServiceLocator to help us to achieve it.

We could say that HelloWorldBO is like a POJO (Plain Old Java Object) in Java. In other words, a non intrusive class which doesn’t have to implement any interface or to extend any class, being totally decoupled from an execution environment or framework. It’s totally reusable everywhere outside guasax.

In this class we only declare the sayHello method as you can see above. This name matches with method=”sayHello” attribute indicated in the XML configuration file.

Invoking the action

We always have to realize for any action invokation that it’s going to be through a framework which, as we will see in next examples, will provide us with more ways to invoke a method of our business logic. We have some ways to carry on an action invokation, depending on the desired behaviour during the execution.

In this example, we simply call an action, being able to pass an IN params array if necessary. When click event happens, guasax container passes the identifier (a String) of the action to be executed to executionAction method and the params array (null if no params). In this case we pass null because there are no params to pass.

If there were params it will be passed as an array in the provided order.

If we need to get the returned value from the executing BO method, we will always receive a ResponseActionVO object which has a getResult() method to retrieve the real object returned in the BO method. For example:

In the method execution we only show an Alert message, but we will tipically modify our application model, call remote services,etc.

Links, resources and code

Link to the example HelloWorld online with viewSource option enabled

We encourage you to visit WedTool WedTool
Web design: Ricardo Tayar
Graphic design: Luis Miguel Ferrer