On top of providing the gluing between Seam and Flex, Flamingo ships with a couple of goodies that can’t be ignored. SeamBinding automatically synchronizes Seam and Flex object and SeamValidator performs Flex validation based on server side rules (all the code samples are taken from this demo).
Validation
When you create database tables you specify a set of rules for each field. Say the field can’t be null, it must have more than 5 characters, etc. These rules must be enforced on the front end as well. In Flex we’d have to create validators for each field and for each rule to make sure that we don’t break any of the database constraints. Flamingo’s SeamValidator automatically validates Flex elements based on server side constraints.
On the server side the database management is done by Hibernate so we just need to specify rules for each field (CommandItem.java):
@Length(min=3, max=40) private String command;
Flamingo automatically checks against Hibernate rules and performs the validation directly on Flex objects (silvafug.mxml):
<flamingo:SeamValidator id="validator" destination="commandItem"
source="{commandInput}" validationTarget="command"
property="text" />
<mx:TextInput id="commandInput"/>
<mx:Button label="Validate Command" click="validator.validate()"/>
That’s all what it takes for the magic to happen. Pretty neat, isn’t it?
Binding
Binding a Flex and a Java Object can be done automatically using Flamingo’s SeamBinding. Note that we can get the same results with RemoteObjects (pass the object to the server as an argument - see the post on Remote Calls) but SeamBinding simplifies our lifes a bit by removing some extra steps.
Say we have a Java Object (CommandItem.java):
@Name("commandItem")
@Entity
@Scope(SESSION)
public class CommandItem implements Serializable
{
private static final long serialVersionUID = 1892843745280885007L;
@Id @GeneratedValue
private Integer dbID;
@Length(min=3, max=40)
private String command;
private Integer distance;
public Integer getDbID() {
return dbID;
}
public void setDbID(Integer dbID) {
this.dbID = dbID;
}
public String getCommand() {
return command;
}
public void setCommand(String command) {
this.command = command;
}
public Integer getDistance() {
return distance;
}
public void setDistance(Integer distance) {
this.distance = distance;
}
}
and a Flex object (CommandItem.as):
[RemoteClass(alias="com.java.package.CommandItem")]
[Bindable]
public class CommandItem
{
public var dbID:int;
public var command:String;
public var distance:int;
}
then SeamBinding seamlessly keeps the 2 objects synchronized. All we need to do is connect the 2 objects and call on commit or update depending on which direction we want to perform the synchronization (silvafug.mxml):
<flamingo:SeamBinding destination="commandItem"
id="bindingService" source="{commandItem}"/>
<mx:Button label="Do Something" click="bindingService.commit()"/>
Tada! When bindingService.commit() is called we got our client side object automatically saved in the server session. If we want it stored in the database all we’d have to do is to persist the server side object.


