Archive for May, 2010

Using the Spinner control in flex 4

May 12, 2010

The Spinner control is an alternate to NumericStepper’s in Flex 4. The advantage is while it works with ranges, it is not hard bound to a numeric input. You can choose to step through a collection and display images or any other content.

Spinner Control Sample App

Spinner Control Example in Flex 4

Below is some code which associates text from a collection to the numeric stepper as seen in image above.

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"  width="350" height="150">

<fx:Script>
<![CDATA[

import mx.collections.ArrayCollection;
[Bindable] private var dataColl:ArrayCollection = new ArrayCollection
(["Flex","Flash","Catalyst","Slider","FlashLite","DeviceCentral"])
]]>
</fx:Script>

<s:HGroup x="50" y="58" verticalAlign="middle" >
<s:RichText textAlign="right" width="200" text="{dataColl.getItemAt(spinner.value)}"/>
<s:Spinner id="spinner" minimum="0" maximum="{dataColl.length - 1}"/>
</s:HGroup>


<s:Label x="78" y="38" text="Click on the arrows to change values"/>
</s:Application>

LCDS – how it all works

May 11, 2010

We have been consulting/training on LCDS for some time now there is a common need for an overview from a working perspective which helps decide whether to go with it or not.

This article is one such effort to shed some light on how it all works

LCDS is a Java web project which enables Flex/AIR clients to invoke Java methods, concurrently update clients, and supports proxy. It mainly contains 2 things

  1. A webserver
  2. A socket – server

So why is LCDS required?
One of the reasons for which it (and BlazeDS) are widely used is: Clients like Flex/Flash/AIR can publish data in an AMF format. AMF is a binary protocol and hence the footprint of data is lighter so it travels much faster over the network.

Java does not have native support to understand AMF (which is an Open Spec. protocol). LCDS contains a suite of Java classes which deserializes AMF data and passes it to Java as a Java data type.

It primarily has 4 types of services:

  1. (HTTP)Proxy Service
  2. Remoting Service
  3. Messaging Service
  4. Data Management Service

All these services are supported by protocols. A protocol defines how data is passed to the Java layer.

3 key protocols supported are are:

  1. HTTP
  2. AMF
  3. RTMP

You can also use variants like AMFX (non – binary XML version of AMF). These protocols are used to pass message objects via a Channel. A message object is the entity that Flex want’s to send across

There are  various channels that support these protocols

AMF, Secure AMF, HTTP, RTMP, Secure RTMP, NIO – AMF, NIO RTMP and others.

You can select a channel depending on the type of communication you want to establish.

Each of these Channels are associated with end points. So a message objects travels over a channel and hits an end point on the LCDS server. Making an endpoint unique for a channel

There are 2 types on end-points:

  1. Serverlet based end point (typically the MessageBroker Servlet) – Uses a webserver
  2. Socket based end point – these are more scalable (NIO/RTMP) – Uses a socket server

Once a message has hit the end point, It starts its journey inside the LCDS server. Here it goes through a series of layers starting from

  • The MessageBroker -Here is where authentication takes place, and the service is identified for the message
  • The Service is identified and one of these HTTPProxyService/RemotingService/DataService/MessagingService is invoked Depending on the destination of the message.
  • This destination is set by Flex in the message when it serializes it. The association between Flex and your Java Service is mapped using a destination.

Flex - LCDS Destination - Java
Flex – LCDS Destination – Java

  • Finally the Adapter kicks in. This is the entity responsible of invoking the Java class and passing data. This Adapter depends on the service that you use
  • Typically for a DataService (read Data Management Service) there is another layer of Assembler which could be either a standard from LCDS or custom created depending on the back-end or the data tier.

LCDS has in built assemblers for Hibernate and others.

The entire flow can be summarized as:

Flex LCDS Communication

Flex LCDS Communication

That, in a nutshell, speaks about LCDS. Most things also apply for BlazeDS. If you have queries/suggestions/comments. Please feel free to put them in the comments section.

Y