Binding to server-side context variable from JavaFX

In addition to calling methods and Hibernate Validator, it’s also very simple to bind to a context variable and update it from JavaFX. A context variable is any variable inside a scope on the server.


Seam component:

@Name ("shop")
@Scope (ScopeType.SESSION)
public class Store {

   IceCream iceCream; // getter and setter

   public void init (){
	iceCream = new IceCream();
	iceCream.setName("Best ice cream");


@Name ("icecream")
public class IceCream implements{

   @Max(value=5, message="Sorry, you can't have more than {value} flavors")
   private Integer flavors;

   private String name;

   // getters and setters



public class IceCream implements{
   private String name;
   private Integer flavors;
   // setters and getters

BindingManager interface:

public interface BindingManager {
   public String commit(String componentName, Object value);
   public Object getObject(String name);
public class IceCreamServiceFactory {
   public static BindingManager getBindingManager() {
	return (BindingManager) FXServiceFactory.getService(BindingManager.class,
   public static String commit (String componentName, Object value){
	return getBindingManager().commit(componentName, value);
   public static IceCream getIceCream (String componentName){
	return (IceCream)getBindingManager().getObject(componentName);

JavaFX script:

CookieHandler.setDefault(new CookieManager(null,CookiePolicy.ACCEPT_ALL));
FXServiceFactory.URL = "http://localhost:8080/server-javafx/seam/resource/hessian/";

FX.println("Getting ice cream from server");
var iceCream = IceCreamServiceFactory.getIceCream('shop.iceCream');
FX.println ("  {iceCream}");

iceCream.setName ("Gelato");

FX.println("Starting commit");
IceCreamServiceFactory.commit("shop.iceCream", iceCream);
FX.println("Getting ice cream from the server after update");
FX.println ("   {IceCreamServiceFactory.getIceCream('shop.iceCream')}");

Line 5: Getting ice cream from the server (binding to context variable)
Line 8-9: Making changes to ice cream
Line 12: Committing changes to the server
Line 14: Getting the updated object from the server


Getting ice cream from server
  Name: Best ice cream, flavors: 2
Starting commit
Getting ice cream from the server after update
   Name: Gelato, flavors: 4

That’s it.


Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.