This is an introductory post that shows how to use JavaFX with JBoss Seam. Communication between JavaFX and server (Seam) is done via Flamingo RIA framework. Flamingo, not only provides Flex to server communications like Granite DS and Blaze DS, but also provides JavaFX to server communications.

JavaFX:
package com.exadel.flamingo.javafx;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.TextOrigin;
import javafx.ext.swing.SwingButton;
import javafx.scene.layout.VBox;
import javafx.scene.control.TextBox;
import com.exadel.flamingo.javafx.samples.helloworld.javafx.HelloworldClient;
class Hello {
public var name:String;
public var str:String;
}
var helloModel = new Hello();
HelloworldClient.setServerUrl(FX.getArgument('uri') as java.lang.String);
var helloText: TextBox = TextBox {
text: bind helloModel.name with inverse
columns: 7
selectOnFocus:true
}
var helloLabel = Text{
y:8
font: Font { name:"sansserif", size: 12 }
fill: Color.BLACK
content: bind "Server says: {helloModel.str}"
textOrigin: TextOrigin.TOP
}
var helloButton = SwingButton {
text:"Say Hello!"
action: function(){
helloModel.str = HelloworldClient.CLIENT.hello(helloModel.name);
}
}
Stage {
title: "Helloworld Sample"
width: 200
height: 150
scene: Scene {
content: VBox {
translateX: 5
translateY: 5
spacing: 10
content: [
HBox {
content: helloText
spacing: 10
},
HBox {
content: helloButton
spacing: 10
},
HBox {
content: helloLabel
spacing: 10
}]
}
}
}
HelloAction interface:
package com.exadel.flamingo.javafx.samples;
import org.jboss.seam.annotations.remoting.WebRemote;
public interface IHelloAction {
@WebRemote
public String hello(String name);
}
HelloAction (Seam component):
package com.exadel.flamingo.javafx.samples;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.remoting.WebRemote;
@Scope(ScopeType.STATELESS)
@Name("helloAction")
public class HelloAction implements IHelloAction {
@WebRemote
public String hello(String name) {
return "Hello, " + name;
}
}
Helloworld client:
package com.exadel.flamingo.javafx.samples.javafx;
import com.caucho.hessian.client.HessianProxyFactory;
import com.exadel.flamingo.javafx.samples.IHelloAction;
import java.net.MalformedURLException;
public class HelloworldClient {
public static HelloworldClient CLIENT;
private IHelloAction _service;
private String _url;
private HelloworldClient(String string) {
_url = string;
}
public static void setServerUrl(String url) {
CLIENT = new HelloworldClient(url);
}
private IHelloAction getService() {
if (_service == null) {
try {
HessianProxyFactory factory = new HessianProxyFactory();
_service = (IHelloAction) factory.create(IHelloAction.class, _url);
} catch (MalformedURLException ex) {
System.out.println(ex);
}
}
return _service;
}
public String hello(String s) {
return getService().hello(s);
}
}
JSP file:
HelloworldJavaFX with Seam!
javafx( { archive: "jnlp/helloworld-client-javafx.jar", draggable: true, width: 600, height: 560, code: "com.exadel.flamingo.javafx.MainFrame", name: "Helloworld", uri:'' } );
Leave a comment