Seam and Flex

by Shashank Tiwari

JBoss Seam and Adobe Flex are two promising technologies. Seam makes it easy to build stateful web applications. It integrates the Java EE frameworks together. Flex is a great rich application development framework. The question is can they and should they be used together?

Seam till its 1.x versions used JSF as the main UI framework. This implied that it was built around a server side UI model. Flex on the contrary is a client side UI framework. Oops! so we have a big disconnect right away! Not really, there possibly are some viable options to make them work together. In the latest version of Seam 2.0.0 BETA the coupling with JSF has been loosened. Also, in the past its been demonstrated that JavaScript UIs (built on frameworks like DOJO or any other) could directly remote to Seam server side components. Remember though that JavaScript runs within the browser whereas Flex applications runs within the Flash VM. Does that matter?One option is to have Flex as the front end and make Flex components remote to Seam? Technically this is a possibility and may be good in situations where Flex is used as a pure view description technology. In fact has anybody wondered writing a JSF render kit for Flex? That would be one nice looking but ugly under the hood hack. The state and event management would be all mixed up and one would end up writing more wiring to save the two together than use in isolation. I know some of you may oppose this thought and may cite cases where you have used Applets as a face for Servlets or similar server side technologies. Yes it works, is it elegant though? And what were the big wins of making them work together anyway? This the same question I ask when I read articles that claim that Spring MVC can work smoothly with Flex and Java Portlets can work effortlessly with Flex. Is it better to make complicated applications by spending more time and energy as opposed to building clean applications faster? In other words is it better to do the right thing or focus on making everyone happy?

So what does it mean in the context of our main exploration of making Seam and Flex work together? We have looked at the dry option of remoting a Flex face to a Seam server side. We could possibly liven it up by managing state on both sides - client and server - and introduce something that could be called a State Transfer Object (STO) to transfer the state information back and forth. Doesn't sound good! It reminds me of the pain of using DTOs. Is there any other option? My answer is that I don't know of one yet. I am trying to write a bridge between the two, following the principle of delegation and inclusion of common contexts wherever possible and ofcourse cheating (oh sorry! drawing inspiration) from the JavaScript remoting integration and the GWT integration in the Seam code base. If and when its ready, it would show up as an open source tool for everybody to play with and I will annouce its arrival. BTW, if anyone else here is interested in hacking that with me, you are most welcome to join in. In the meanwhile I would certainly like to hear your experiences in making these two work together. Both real life experiences and armchair musing are welcome.


James Ward
2007-07-10 15:00:21
Cool stuff Shashank! I know Gavin has been wanting some sexy Seam demos for a while. This has been on my to-do list for well over a year, so I'm glad to see that you are jumping in. The two technologies can actually fit very nicely together. And now that Flex is going Open Source these two tools make an even better fit. We should also be exploring how this combination fits into JSR 299, but in a more general way.

Anyways keep up the good work and keep us updated on your progress!


Nicolas Modrzyk
2007-07-10 16:50:28
Hi Shashank,

Looks to me there is also a valid alternative solution:
Both rails and flex, rapid application development, best of both worlds.
IMHO, I would say the choice depends on what other pieces of software, and how, you have to integrate with.


2007-07-11 04:33:25
I spent some of yesterday looking at this exact problem. Most of the solutions I could think of were unappealing.
- Use remoting javascript in host html file & use ExternalInterface
- new flex renderkit
- subclass the remoting module to generate actionscript instead of javascript.
- use webservices. This works right out of the box, however you have to add another stateless session bean to follow the seam recommended webservices approach and some annotations to your domain model so jaxb can serialize it properly.

I am brand new to java, seam, webdevelopment, & flex so I could be way of base here.

What approach are you thinking of?

Shashank Tiwari
2007-07-12 10:53:56
Seam components can be called synchronously or asynchronously. Synchronous calls follow the web service paradigm. A few integrations like DOJO (JavaScript) toolkit and GWT use asynchronous mechanisms. Flex and Seam integration would use some sort of asynchronous communication style. The integration though ideally needs to be tighter - like Seam has with JSF today for the integration to utilize the goodies of both Flex and Seam. I am trying out a few things, not sure what might be the best option though.
Shashank Tiwari
2007-07-12 11:04:06
Thanks for the encouragement! If the two can be made to work together effectively, it would be a fantastic and compelling open source stack for the developers.


Cameron Ingram
2007-07-13 07:27:42
Shashank I agree with your assertions. We are in the process of doing the same thing. I've been looking at what is the best way to approach the problem(remoting, DTO, a bridge) and really haven't come up with a promising answer. Remoting seems to be the easiest but you give up a lot. I think if Seam and Flex can get closer in integration, you will one powerful and quickly built application. I am very interested in this topic if you would like some help in hacking it up please let me know.


2007-08-01 08:41:52
Right now I'm using Flex<->(http+json)<->RESTlet+spring and it doesn't look bad.