[jboss-user] [JBoss Seam] - Seam Flex Integration, How Easy It Is!

cingram do-not-reply at jboss.com
Fri Jul 20 10:57:44 EDT 2007


I have successfully integrated Seam and Flex, and it was really easy!

Through the Seam remoting interface I was able to create a wrapper and an Actionscript object to help with the communication. The Adobe AjaxFlex bridge makes the communication portion from actionscript to javascript fairly simple.  By including a couple javascript files and one actionscript file you can be on your way.  I thought I would include a simple example to show how easy it can be. One thing I find kind of interesting is that you can have a Flex UI and a Facelets UI in the same project, both using the same backend. The Seam guys did a really great Job on the remoting interface which is what makes this possible!

Here is an example of the Actionscript code.

  | 
  |    <fab:FABridge xmlns:fab="bridge.*" />
  | 
  |    private var seamBridge:SeamBridge = new SeamBridge();
  | 
  |    private function sayHello(): void {
  |    seamBridge.setSeamComponent("helloAction");
  |    seamBridge.setMethod("sayHello");
  |    seamBridge.addParam(txtName.text);
  |    seamBridge.setCallBackMethod("sayHelloCallBack");
  |    seamBridge.callServer();
  |  }
  | 
  |  public function getNameCallBack(result: String): void {
  |    Alert.show(?Hello ? + result + ? I am from Seam?;
  |  }
  |  


This is what you would use for your Seam code. Looks familiar doesn?t it?  As a matter of fact it is from the Seam remoting example. This could easily be changed to a stateful bean and have it return a var or even an object.


  | package org.jboss.seam.example.remoting;
  | 
  | import javax.ejb.Stateless;
  | 
  | import org.jboss.seam.annotations.Name;
  | 
  | @Stateless
  | @Name("helloAction")
  | public class HelloAction implements HelloLocal {
  |   public String sayHello(String name) {
  |     return "Hello, " + name;
  |   }
  | }
  | 
  | 
  | package org.jboss.seam.example.remoting;
  | 
  | import javax.ejb.Local;
  | import org.jboss.seam.annotations.WebRemote;
  | 
  | @Local
  | public interface HelloLocal {
  |   @WebRemote
  |   public String sayHello(String name);
  | }
  | 
  | 

The encapsulating html page must include the following references.  Per the documentation, any object you want to expose via remoting must be referenced in the ?interface.js? line. The ?flexseam.js? file is just a wrapper file for the ?remote.js? to make the communication easier.
 

  | <script src="FlexSeam.js" ></script>
  | <script type="text/javascript" src="seam/resource/remoting/resource/remote.js"></script>
  | <script type="text/javascript" src="seam/resource/remoting/interface.js?helloAction "></script>
  | 

We are in the process of putting a proof of concept together in Flex with a Seam backend. In this manner you have access to all of the contexts within Seam. If anyone feels this is usefull to their projects, please let me know and I will post the code files.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4066237#4066237

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4066237



More information about the jboss-user mailing list