commit | author | age
|
aaf094
|
1 |
package com.redhat.training.ui; |
RS |
2 |
|
|
3 |
import javax.enterprise.context.RequestScoped; |
|
4 |
import javax.faces.application.FacesMessage; |
|
5 |
import javax.faces.context.FacesContext; |
|
6 |
import javax.inject.Named; |
|
7 |
import javax.validation.ConstraintViolation; |
|
8 |
import javax.validation.ConstraintViolationException; |
|
9 |
|
|
10 |
import com.redhat.training.model.Person; |
|
11 |
import com.redhat.training.services.PersonService; |
|
12 |
|
|
13 |
import javax.inject.Inject; |
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
@RequestScoped |
|
17 |
@Named("hello") |
|
18 |
public class Hello { |
|
19 |
private String name; |
|
20 |
private Long id; |
|
21 |
|
|
22 |
@Inject |
|
23 |
private PersonService personService; |
|
24 |
|
|
25 |
public void sayHello() { |
|
26 |
try { |
|
27 |
String response = personService.hello(name); |
|
28 |
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(response)); |
|
29 |
}catch(Exception e){ |
|
30 |
System.out.println(e.getCause()); |
|
31 |
if(e.getCause() != null && e.getCause() instanceof ConstraintViolationException) { |
|
32 |
ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); |
|
33 |
String violations = ""; |
|
34 |
for(ConstraintViolation<?> cv: ex.getConstraintViolations()) { |
|
35 |
|
|
36 |
violations += cv.getMessage() + "\n"; |
|
37 |
|
|
38 |
System.out.println("Violations: "+violations); |
|
39 |
} |
|
40 |
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(violations)); |
|
41 |
} |
|
42 |
|
|
43 |
} |
|
44 |
|
|
45 |
} |
|
46 |
|
|
47 |
public String getName() { |
|
48 |
return name; |
|
49 |
} |
|
50 |
|
|
51 |
public void setName(String name) { |
|
52 |
this.name = name; |
|
53 |
} |
|
54 |
|
|
55 |
public Long getId() { |
|
56 |
return id; |
|
57 |
} |
|
58 |
|
|
59 |
public void setId(Long id) { |
|
60 |
this.id = id; |
|
61 |
} |
|
62 |
|
|
63 |
/*public void getPerson() { |
|
64 |
try { |
|
65 |
String response = personService.getPerson(id); |
|
66 |
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(response)); |
|
67 |
}catch(Exception e){ |
|
68 |
System.out.println(e.getCause()); |
|
69 |
if(e.getCause() != null && e.getCause() instanceof ConstraintViolationException) { |
|
70 |
ConstraintViolationException ex = (ConstraintViolationException) e.getCause(); |
|
71 |
String violations = ""; |
|
72 |
for(ConstraintViolation<?> cv: ex.getConstraintViolations()) { |
|
73 |
|
|
74 |
violations += cv.getMessage() + "\n"; |
|
75 |
|
|
76 |
System.out.println("Violations: "+violations); |
|
77 |
} |
|
78 |
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(violations)); |
|
79 |
} |
|
80 |
|
|
81 |
} |
|
82 |
|
|
83 |
}*/ |
|
84 |
|
|
85 |
|
|
86 |
/*public List<Person> getPersons() { |
|
87 |
return personService.getAllPersons(); |
|
88 |
|
|
89 |
}*/ |
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
} |