Invoking Hibernate Validator from JavaFX

I showed how to call a Seam component with Flamingo from JavaFX. In this post I show how to invoke Hibernate Validator from JavaFX with Flamingo:

Entity (and Seam component):

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

   @Id @GeneratedValue
   private Long id;

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

   // getters and setters
}

JavaFX script (most interesting stuff is happening lines 17-21):

FXServiceFactory.URL = "http://localhost:8080/server-javafx/seam/resource/hessian/";

var message:String;
var textBox:TextBox = TextBox {
    columns: 15
}
var label:Label = Label {
    text : "How many flavors:"
    style:"-fx-font-weight:bold"
}
var errorMessage:Label = Label {
    text: bind message
    style : "-fx-text-fill:red; -fx-font-weight:bold"
}
var button:Button = Button {
    text: "Click"
    action : function () {
       var ev = FXServiceFactory.getService(EntityValidator.class,
       		"com.exadel.flamingo.service.validator.entityValidator")
       		as (EntityValidator);
       message = ev.validate ("icecream.flavors", textBox.text)
    }
}

Stage {
    title: "Application"
    width: 250 height: 100
    scene: Scene {
        content: [
        VBox {
            spacing: 5
            content:[
            label,
            HBox {
                spacing: 5
                content: [
                   textBox,
                   errorMessage
                ]
            }
            button
            ]
        }
        ]
    }
};

Result:

That’s it.

One thought on “Invoking Hibernate Validator from JavaFX

  1. Pingback: Seam conversations from JavaFX | Maxa Blog

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s