So what's in this first implementation :
Note that for now it will work only with the Weld implementation, as conversation support requires using some non public JSR-299 API.
Also the supported containers are for now JBoss 5.2 trunk (available here and GlassFish V3 starting from build 70 (available here). It will probably not work in Tomcat for now.
The GraniteDS distribution contains a graniteds-tide-jcdi example that can be deployed in any of these application servers.
Configuration
The configuration is almost the same as for other server framework integrations and consists in five parts :<granite-config scan="true">
<security type="org.granite.messaging.service.security.TomcatSecurityService"/>
<tide-components>
<tide-component instance-of="org.granite.tide.jcdi.JCDIIdentity"/>
<tide-component annotated-with="org.granite.messaging.service.annotations.RemoteDestination"/>
</tide-components>
</granite-config>
<factories>
<factory id="tideJcdiFactory" class="org.granite.tide.jcdi.JCDIServiceFactory"/>
</factories>
Remoting
Once this is done, add your named JCDI bean and annotate it with @RemoteDestination :
@Named("helloWorld")
@RemoteDestination(id="helloWorld")
public class HelloWorld {
public String hello(String name) {
return "hello" + name;
}
}
Then you can easily call it from Flex using Tide remoting and injection :
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns="*"
preinitialize="Jcdi.getInstance().initApplication()">
<mx:Script>
<![CDATA[
import org.granite.tide.jcdi.Jcdi;
import org.granite.tide.Component;
[In]
public var helloWorld:Component;
]]>
</mx:Script>
<mx:Button label="Hello" click="helloWorld.hello('Barack')"/>
</mx:Application>
You can even use typesafe client proxies (e.g. public var helloWorld:HelloWorld) if you have generated them with gas3. Maybe in RC2 we'll try to use completely typesafe service invocation and will not require @Named beans any more.
Events
Support for events is relatively similar to what exists for Seam, but with JCDI it uses typesafe events.Define your Java and as3 event classes (in the final release it will be possible to generate the as3 event class automatically with gas3) :
public class GreetingEvent {
private String name;
public GreetingEvent(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
[RemoteClass(alias="test.app.GreetingEvent")]
public class GreetingEvent extends AbtractTideEvent {
public var name:String;
}
Fire an event from the server method :
@Named("helloWorld")
@RemoteDestination(id="helloWorld")
public class HelloWorld {
@Inject @Any
EventgreetingEvent;
public String hello(String name) {
greetingEvent.fire(new GreetingEvent(name));
return "hello" + name;
}
}
Then just declare a remote observer in the Flex application and it will be triggered whenever the event is dispatched during a remote call initiated from Flex.
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns="*"
preinitialize="Jcdi.getInstance().initApplication()">
<mx:Script>
<![CDATA[
import org.granite.tide.jcdi.Jcdi;
import org.granite.tide.Component;
[In]
public var helloWorld:Component;
[Observer(remote="true")]
public function greet(event:GreetingEvent):void {
trace("Greeting to " + event.name);
}
]]>
</mx:Script>
<mx:Button label="Hello" click="helloWorld.hello('Barack')"/>
</mx:Application>
This is really just an early implementation of this integration and it will be updated for the final release of the JCDI specification and RI.
Our feeling is that JCDI is a perfect fit for Flex RIAs with an event-driven architecture. JCDI applications looks extremely clean and even JBoss Seam provides a lot more features, they do not necessarily make sense with a RIA front-end.
Feel free to give some feedback and maybe some ideas for this integration.