-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
FormFactory.java
78 lines (66 loc) · 2.25 KB
/
FormFactory.java
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Copyright (C) 2009-2017 Lightbend Inc. <https://www.lightbend.com>
*/
package play.data;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.validation.Validator;
import play.i18n.MessagesApi;
import play.data.format.Formatters;
/**
* Helper to create HTML forms.
*/
@Singleton
public class FormFactory {
private final MessagesApi messagesApi;
private final Formatters formatters;
private final Validator validator;
@Inject
public FormFactory(MessagesApi messagesApi, Formatters formatters, Validator validator) {
this.messagesApi = messagesApi;
this.formatters = formatters;
this.validator = validator;
}
/**
* @return a dynamic form.
*/
public DynamicForm form() {
return new DynamicForm(messagesApi, formatters, validator);
}
/**
* @param clazz the class to map to a form.
* @param <T> the type of value in the form.
* @return a new form that wraps the specified class.
*/
public <T> Form<T> form(Class<T> clazz) {
return new Form<>(clazz, messagesApi, formatters, validator);
}
/**
* @param <T> the type of value in the form.
* @param name the form's name.
* @param clazz the class to map to a form.
* @return a new form that wraps the specified class.
*/
public <T> Form<T> form(String name, Class<T> clazz) {
return new Form<>(name, clazz, messagesApi, formatters, validator);
}
/**
* @param <T> the type of value in the form.
* @param name the form's name
* @param clazz the class to map to a form.
* @param groups the classes of groups.
* @return a new form that wraps the specified class.
*/
public <T> Form<T> form(String name, Class<T> clazz, Class<?>... groups) {
return new Form<>(name, clazz, groups, messagesApi, formatters, validator);
}
/**
* @param <T> the type of value in the form.
* @param clazz the class to map to a form.
* @param groups the classes of groups.
* @return a new form that wraps the specified class.
*/
public <T> Form<T> form(Class<T> clazz, Class<?>... groups) {
return new Form<>(null, clazz, groups, messagesApi, formatters, validator);
}
}