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):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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 comment

  1. Pingback: Seam conversations from JavaFX | Maxa Blog

Leave a Reply