Seam and Flex

Posted by    |       Seam

If the forums are any indication, there's quite a bit of interest in the Seam community for adding Flex interfaces to Seam applications. Members of the seam community have stepped forward and put together some interesting examples of Seam and Flex working together, and that's been good enough for our more ambitious users. But now it's time to make that integration a bit more formal. So with that, we've added the first round of Flex support to Seam.

We're starting with a simple solution for Flex remoting to Seam applications using BlazeDS. Getting going with Seam involves adding jboss-seam-flex.jar to your application, along with the BlazeDS libraries. The BlazeDS MessageBroker, which responds to requests from the Flex client, is instantiated and managed my the Seam Flex filter:

<flex:flex-filter url-pattern="/messagebroker/*" />

With that, your Flex application can talk to your Seam application. Obviously it wouldn't be wise to expose all your Seam components for remote access automatically. Individual components can be enabled for Flex remoting with a single annotation:

public class Foo
   public void ping() {

This annotation causes Seam to add a named remoting destination on the default channel, which can immediately be accessed as a \<mx:RemoteObject> in a Flex application. The minimal mxml on the client side would be:

<mx:RemoteObject id="remoteFoo" destination="foo" />

This declares a remote objection. The destination name should match the destination name on the @FlexRemote annotation.

<mx:Button id="button" label="Click Me!" click="" />

This creates a button, that when pressed calls the remote method. Dealing with results and errors requires a little more code than this, but it works the same as any other Flex remote object.

One of the nice things about Flex remoting is how simple it is to pass complex data structures around. For example, suppose you are writing a Flex client to work with the hotel data in the Seam booking application. If your Seam components had the following:

public List<Hotel> queryAllHotels() {
   return entityManager.createQuery("select h from Hotel h").getResultList();

Then the entire data set could be loaded into the table quite easily.

<mx:RemoteObject id="remoteFoo" destination="foo" fault="fault(event)">
    <mx:method name="queryHotels"
               result="hotelTable.dataProvider=ResultEvent(event).result" />

<mx:DataGrid id="hotelTable" />
<mx:Button label="Query Hotels" click="remoteFoo.queryHotels()" />

Note here that the remoting is smart enough to figure out the column names and values to display based on the Java objects returned, with no extra coding. It may not be production ready, but it makes for a great demo.

So, if you want to use Flex and Seam together, how can you give this a try? The Flex module is under development in the Seam22 branch. At this point we only support the basic remoting shown here and don't support conversation or business process scoped components, since the correct mapping of conversations to a rich client is not entirely obvious. If you can live with that, or if you'd like to help contribute to the future development of the Flex module, please jump in on the forums and provide some feedback.

Back to top