Flex Pasta » Flex 4

2 1/2 years ago I published annotations for BlazeDS that allowed for placing tags on Java getters/setters to determine if a value is serialized to the Flex client.  Soon I will publish a 3 part BlazeDS extension that does the following(with annotations of course).

  1. Serialization Profiles with BlazeDS - This was mentioned in a previous post and I will be releasing this soon along with the rest of the annotations code.
  2. Mate Code Generator - More details to come, but if you are familiar with the Mate Framework, this code generator will create complete EventMaps/DataManagers/Events from Java services(and it runs for the life of the project).
  3. Model Code Generator  - This isn’t the kind where a button is pressed once to create Flex remote object bean classes.  I don’t like code generators that only generate the file initially.  I also don’t like when a code generator creates generated code that then the developer must extend(ex: Customer extends _Customer).  I have created a code generator that does neither but still can be run endless times for the life of the project.  Here is an example output file.  The developer can add any code to the area marked as such in comments.  Every time the generator is run it will clear out the rest of the file and regenerate the properties from the matching Java class.
    /* File Generated by FlexPastaDomainGenerator v. 1.0
    * Only edit the file in the designated area.
    * All other changes will be lost
    */
    package com.company.model
    {[Bindable]
    [RemoteClass(alias=”com.company.model.Address”)]
    public class Address
    {
    public var country:String;
    public var lot:String;
    public var parcel:String;
    public var state:String;
    public var streetName:String;
    public var streetNumber:String;
    public var subdivision:String;
    public var uuid:String;
    public var zipCode:String;

    //**********EDIT AREA**********

    //**********END EDIT**********
    }
    }

Looks for more details in the coming weeks!

A hand full of bugs have been field with Adobe’s Flash Player regarding problems uploading with Firefox.

https://bugs.adobe.com/jira/browse/FP-78
https://bugs.adobe.com/jira/browse/FP-1044
https://bugs.adobe.com/jira/browse/FP-419
https://bugs.adobe.com/jira/browse/FP-201
https://bugs.adobe.com/jira/browse/FP-568

There have also been plenty of posts describing the problem.

http://sethonflex.blogspot.com/2007/10/flex-and-filereferenceupload-using.html
http://thanksmister.com/index.php/archive/firefox-flex-urlrequest-and-sessions-issue/
http://stackoverflow.com/questions/351258/how-do-i-make-flex-file-upload-work-on-firefox-and-safari

In Flash 9, there is really no good way around this problem.  However, in Flash 10 / Flex 4, an enhancement to flash.net.FileReference makes it possible to read the contents of a file before it is uploaded.  Meaning that the file can be uploaded in different ways then can be done in Flash 9.  The following example shows how easy file uploading can be and is not tied to SSL, Firefox, IE, Chrome, etc.  This method is using Java server side with BlazeDS, but could be modified to work with other setups.

First, look at the application file.

<?xml version=”1.0″ encoding=”utf-8″?>
<s:Applicationxmlns:fx=”http://ns.adobe.com/mxml/2009 xmlns:s=”library://ns.adobe.com/flex/spark xmlns:mx=”library://ns.adobe.com/flex/halo” minWidth=”1024” minHeight=”768>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Declarations>
<!–
Place non-visual elements (e.g., services, value objects) here –>

<s:RemoteObject id=”upload” destination=”uploadService” endpoint=”http://localhost/Context/messagebroker/amf/>
</fx:Declarations>

<fx:Script>
<![CDATA[
private var fr:FileReference = new FileReference();

private function test():void
{
fr.browse();
fr.addEventListener(Event.SELECT, selected);
fr.addEventListener(Event.COMPLETE, complete)
}
private function selected(event:Event):void
{
fr.load();
}
private function complete(event:Event):void
{
var byteArray:ByteArray = fr.data;
upload.uploadFile(byteArray);
}
]]>
</fx:Script>

<s:Button label=”Upload” click=”test()”/>
</s:Application>

Notice the fr.load();  This will actually load the file and make it’s contents available to us in the code.  The complete handler than takes those contents as a byte array and calls the remote “uploadService” passing in that byte array.  Here is the simple Java code for the service method “uploadFile”:

public void uploadFile(byte[] file)
{
// Do something here to save the file
}

It is that easy in Flash 10.  By allowing access to the file, the upload process is quick and painless.

While still a work in progress, a new set of features will exist for text layout in Flex 4/Flash 10.  The package name for the text layout library is flashx.*, which is a shift from traditional Flex packages, but it looks like it will be open source.  Here is a demo with a simple slider that changes the width of the first column and the text automatically lays itself out across multiple components.  While I couldn’t get it to work yet(still beta), the final product will allow html formatting(actually a limited number of html tags).  For applications that are heavy on content related material, it will be huge that text can be strung across multiple components from one string variable.  The string will automatically re-size and position itself dynamically.  Now while I am not doing these features justice, here is a small example of the layout.

Read the rest of this entry…

A while back I did a post on the choppiness of mx:List scrolling and a mx:Repeater work around FTW(For the Win).  Well in Flex 4, the List component will be FTW out of the box!!!  Meaning, smooth scrolling item renderers!!  It looks like the Flex SDK team has spent some time improving the quality, scrolling, and layout of item renderers.  Here side by side are the examples from a Flex 3 List compared to the same code in a Flex 4 List.  Check out the difference!

Flex 3 List with Image Scrolling

Flex 4 List with Image Scrolling

The Flex development landscape has many frameworks for creating scalable, enterprise RIA applications.  The two major players, in my opinion, are Cairngorm and Mate.  Both frameworks offer a solid approach to an enterprise RIA.  Having used both Cairngorm and Mate in enterprise Java applications, Mate is the better option for small and large projects(in my opinion).  Cairngorm uses a singleton pattern that makes it hard to use modules and requires significant more overhead in compile times, SWF size, and speed of development.  Mate on the other hand uses an injection approach which is easy and fast to create, maintain, and debug applications.  I am not saying you are going wrong by using Cairngorm, but my first choice is Mate.

Cairngorm development dead; Mate booming

Cairngorm was purchased by Adobe and eventually open sourced.  Since being opened source in an SVN repository in July 2008, Cairngorm has had a total of 0 new releases, 15 total commits and no commits since November 2008.  The last code release of cairngorm has not been since Flex 2.  Mate on the other hand is also open source.  Mate had 17 new releases in the last year alone with hundreds of commits to its repository.  No other Flex framework out there that I have seen has this amount of activity.

Mate and the Bus Factor

There are a few downsides to Mate that don’t having anything to do with the code.  The bus factor.  Mate is run by a few people at asfusion.  They do a great job at updating the forums, providing documentation, and doing presentations at various Flex events across the country.  However, if they decide to change careers or just get overwhelmed maintaining Mate, there may be no one there to step in to keep the framework going.  I would like to see Mate gain wider support with its code base, with more people committing code and making decisions for the framework’s direction.

A 1.0 release of Mate is also desirable.  The code is quite stable, but a 1.0 release would give a safer feeling to enterprise projects using it.

Support Both or Support None

Adobe bought Cairngorm several years ago.  This was a good idea to help with the development of Flex RIAs.  Now the Flex SDK and Cairngorm are open source.  This completely changes the game.  It appears no one is working on Cairngorm or looking for enhancements for things like modules.  There also appears to be no community involvement for this project.  At what point does Adobe change its direction for a framework?  Will Cairngorm still be the Adobe framework of choice 5 years from now?  Flex 4 is the time to make the change.  One option is to offer both Cairngorm and Mate as preferred frameworks for Flex.  But then the question is, who maintains these frameworks?  A second option would to be supporting no one framework.  This way the community can drive the direction of RIA development by using the best available framework.  It has worked over the years with Struts, Spring, Hibernate, Apache, etc.

By supporting just one framework, the door for innovation of frameworks is closed.  The Flex SDK continuosly improves and excites the community.  Allowing the community to improve the frameworks would be a great step foward.