UserView.java
3.92 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package fi.insomnia.bortal.view;
import java.math.BigDecimal;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.ListDataModel;
import javax.persistence.Column;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.insomnia.bortal.UserBeanLocal;
import fi.insomnia.bortal.db.User;
@ManagedBean(name = "userView")
@SessionScoped
public class UserView {
@EJB
private UserBeanLocal userBean;
//
// private String name;
// private String password;
// private String nick;
// private String email;
// private String address;
// @Column(length = 11)
// private String zip;
private User currentUser;
private String nick = "default";
private String password = "default";
private String realname = "default";
private String email = "default";
private String address = "default";
private String town = "default";
private String phone = "default";
private Boolean female = false;
private String zip = "default";
private ListDataModel<User> items;
public UserBeanLocal getUserBean() {
return userBean;
}
public void setUserBean(UserBeanLocal userBean) {
this.userBean = userBean;
}
public Boolean getFemale() {
return female;
}
public void setFemale(Boolean female) {
this.female = female;
}
public ListDataModel<User> getItems() {
return items;
}
public void setItems(ListDataModel<User> items) {
this.items = items;
}
public String getNick() {
return nick;
}
public String getEmail() {
return email;
}
public String getAddress() {
return address;
}
public String getTown() {
return town;
}
public String getPhone() {
return phone;
}
public String getZip() {
return zip;
}
private static final Logger logger = LoggerFactory.getLogger(UserView.class);
public String saveUser() {
logger.info("Saving user");
// Luodaan uusi kyttj UserBeanin funktiolla createNewUser jolle
// annetaan parametrina pakolliset tiedot ( nick ja salasana )
// Paluuarvona saadaan uusi uljas kyttj-olio.
currentUser = userBean.createNewUser(nick, password);
if (currentUser == null) {
logger.warn("Could not create user. function returned null!");
return "fault";
}
// asetetaan muut kentt..
currentUser.setName(realname);
currentUser.setAddress(address);
currentUser.setNick(nick);
currentUser.setZip(zip);
currentUser.setEmail(email);
currentUser.setTown(town);
currentUser.setPhone(phone);
currentUser.setFemale(female);
currentUser.setPassword(password);
userBean.mergeChanges(currentUser);
logger.info("Saved current users town to {}", town);
return "list";
}
public void setNick(String nick) {
this.nick = nick;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getRealname() {
return realname;
}
public void setRealname(String realname) {
this.realname = realname;
}
public void setCurrentUser(User currentUser) {
this.currentUser = currentUser;
}
public User getCurrentUser() {
return currentUser;
}
public void setFemale(String sex) {
if (sex == "male") {
this.female = false;
} else if (sex == "female") {
this.female = true;
}
}
public void setAddress(String address) {
this.address = address;
}
public void setZip(String zip) {
this.zip = zip;
}
public void setTown(String town) {
this.town = town;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void setEmail(String email) {
this.email = email;
}
public ListDataModel<User> getUsers() {
List<User> users = userBean.getUsers();
items = new ListDataModel<User>(users);
logger.info("Fetching users. Found {}", items.getRowCount());
return items;
}
}