JavaFX and Seam with Flamingo
Client-Side Components
These are non-visual client components that make development easier by providing validation, binding, and the ability to call methods on Seam components. Let's look at these components in more detail.
ServiceFactory
ServiceFactory (com.exadel.flamingo.javafx.ServiceFactory) helps to easily create proxy objects on the client-side. Once proxy objects have been created, it's possible to call any methods on the Seam component. For example, in the JavaFX client:
ServiceFactory.setUrl("http://localhost:8080/flamingods/seam/resource/hessian/");
RegisterAction registerAction = (RegisterAction) ServiceFactory.getService(RegisterAction.class, "registerAction");
RegisterAction is an interface on the client side and registerAction is Seam component name. Now you can call any methods on registerAction component from the client.
SeamServiceFactory
SeamServiceFactory (com.exadel.flamingo.javafx.SeamServiceFactory) is very similar to ServiceFactory but, in addition, creates a client proxy object that automatically supports Seam conversations when performing a server call. You can start/stop a Seam conversion running on the server.
For example, to start/stop a conversion on a client side:
public static void start() {
((RegisterAction)SeamServiceFactory.getService
(RegisterAction.class, "RegisterAction")).start();
}
public static void stop() {
((RegisterAction)SeamServiceFactory.getService
(RegisterAction .class, "RegisterAction")).stop();
}
RegisterAction is an interface on the client side. And on the server side it's a plain Seam component:
@Name("registerAction")
public class ConversationStarter {
@Out
private ConversationObject conversationObject;
@Begin
public void start() {
conversationObject = new ConversationObject();
}
@End
public void stop() {
}
}
Binding
As the name implies, this component
allows binding to a Seam component in one of the Seam contexts from
the JavaFX client.
Server code:
@DataModel
private ArrayList <Car> carList;
Client code:
ArrayList <Student> carList = (ArrayList<Car>)getBindingManager().getObject("carList");
Car is an interface on the
JavaFX side. It's also possible to commit an object
modified in JavaFX back into a Seam context:
Client code:
getBindingManager().commit("user", newUser);
On the server, a user component will be found in one of the Seam contexts and replace newUser.
Validation
This component allows validating user input against Hibernate Validator annotations on the server. Seam component with Hibernate Validator annotations:
@Name ("user")
public class User {
@Length(min=3, max=40)
private String name;
...
}
On the client side, Flaming provides a built-in JavaFX validator component. In the code below, user is Seam component name and name is component property (see above):
message = FlamingoServiceFactory.getHessianEntityValidator().
validate("user.name", inputText.text);
Summary
Part 2 of this series will show how to build an example step by step where we use JavaFX and Seam. Hopefully this article has shown you how simple, easy, and transparent it is to build JavaFX rich clients that are connected to enterprise back-ends such as Seam.
Max Katz is a senior system engineer at Exadel. He is the author of “Practical
RichFaces” (Apress) and co-author of RichFaces DZone RefCard. He has written numerous articles, provided training, and presented at many conferences and webinars about RichFaces and RIA technologies. Max blogs about RichFaces, JavaFX and RIA technologies at http://mkblog.exadel.com.
- Login or register to post comments
- 11488 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)











Comments
Marlet replied on Thu, 2009/07/30 - 7:32pm