Repository navigation
Expand file tree
/
Copy pathContacts.java
More file actions
56 lines (46 loc) · 1.42 KB
/
Copy pathContacts.java
File metadata and controls
56 lines (46 loc) · 1.42 KB
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
package controllers;
import play.*;
import play.mvc.*;
import play.data.*;
import static play.data.Form.*;
import views.html.contact.*;
import models.*;
public class Contacts extends Controller {
/**
* Defines a form wrapping the Contact class.
*/
final static Form<Contact> contactForm = form(Contact.class);
/**
* Display a blank form.
*/
public static Result blank() {
return ok(form.render(contactForm));
}
public static Result edit() {
Contact existingContact = new Contact(
"Fake", "Contact", "Fake company",
new Contact.Information(
),
new Contact.Information(
),
new Contact.Information(
"Previous", "[email protected]"
)
);
return ok(form.render(contactForm.fill(existingContact)));
}
/**
* Handle the form submission.
*/
public static Result submit() {
Form<Contact> filledForm = contactForm.bindFromRequest();
if(filledForm.hasErrors()) {
return badRequest(form.render(filledForm));
} else {
Contact created = filledForm.get();
return ok(summary.render(created));
}
}
}