Update Admin
Added update and remove options to the admin Update option implementedmaster
parent
453e6330ab
commit
f8fd2e8f15
|
@ -41,17 +41,16 @@ public class AdministratorBean {
|
|||
|
||||
//Admin Update
|
||||
|
||||
public void updateAdmin(int id, String password, String name, String email, String role) {
|
||||
public void updateAdmin(int id, String name, String email, String password) {
|
||||
try {
|
||||
Administrator admin = em.find(Administrator.class, id);
|
||||
if (admin == null) {
|
||||
Administrator administrator = em.find(Administrator.class, id);
|
||||
if (administrator == null) {
|
||||
return;
|
||||
}
|
||||
admin.setPassword(password);
|
||||
admin.setName(name);
|
||||
admin.setEmail(email);
|
||||
//admin.setRole(role);
|
||||
em.merge(admin);
|
||||
}
|
||||
administrator.setPassword(password);
|
||||
administrator.setName(name);
|
||||
administrator.setEmail(email);
|
||||
em.merge(administrator);
|
||||
} catch (Exception e) {
|
||||
throw new EJBException(e.getMessage());
|
||||
}
|
||||
|
@ -84,4 +83,5 @@ public class AdministratorBean {
|
|||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ import javax.validation.constraints.Pattern;
|
|||
query="SELECT u FROM User u ORDER BY u.name")
|
||||
public class User implements Serializable {
|
||||
@Id
|
||||
@GeneratedValue(strategy=SEQUENCE, generator = "CUST_SEQ")
|
||||
@Column(name="ID")
|
||||
//@GeneratedValue(strategy=SEQUENCE, generator = "CUST_SEQ")
|
||||
//@Column(name="ID")
|
||||
protected int id;
|
||||
@NotNull
|
||||
protected String password;
|
||||
|
|
|
@ -5,12 +5,15 @@
|
|||
*/
|
||||
package webpackage;
|
||||
|
||||
import static com.sun.xml.ws.security.addressing.impl.policy.Constants.logger;
|
||||
import ejbs.AdministratorBean;
|
||||
import entity.User;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.List;
|
||||
import javax.ejb.EJB;
|
||||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.SessionScoped;
|
||||
import javax.faces.component.UIParameter;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -28,7 +31,10 @@ public class AdministratorManager {
|
|||
private String passwordAdmin;
|
||||
private String nameAdmin;
|
||||
private String emailAdmin;
|
||||
private User currentUser;
|
||||
|
||||
|
||||
|
||||
public String createAdmin() {
|
||||
|
||||
try{
|
||||
|
@ -46,6 +52,30 @@ public String createAdmin() {
|
|||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public String updateAdmin() {
|
||||
try {
|
||||
adminBean.updateAdmin(
|
||||
currentUser.getId(),
|
||||
currentUser.getName(),
|
||||
currentUser.getEmail(),
|
||||
currentUser.getPassword());
|
||||
return "index?faces-redirect=true";
|
||||
} catch (Exception e) {
|
||||
logger.warning("Problem updating user in method updateUser().");
|
||||
}
|
||||
return "admin_update_user";
|
||||
}
|
||||
|
||||
public void removeUser (ActionEvent event) {
|
||||
/* try {
|
||||
UIParameter param = (UIParameter) event.getComponent().findComponent("deleteUserId");
|
||||
int id = param.getValue().toString();
|
||||
adminBean.removeAdmin(id);
|
||||
} catch (Exception e) {
|
||||
logger.warning("Problem removing user in method removeUser().");
|
||||
}*/
|
||||
}
|
||||
|
||||
public AdministratorBean getAdminBean() {
|
||||
|
@ -88,6 +118,13 @@ public String createAdmin() {
|
|||
this.emailAdmin = emailAdmin;
|
||||
}
|
||||
|
||||
public User getCurrentUser() {
|
||||
return currentUser;
|
||||
}
|
||||
|
||||
public void setCurrentUser(User currentUser) {
|
||||
this.currentUser = currentUser;
|
||||
}
|
||||
|
||||
public List<User> getAllUsers() {
|
||||
return adminBean.getAll();
|
||||
|
|
|
@ -21,7 +21,7 @@ and open the template in the editor.
|
|||
id="name"
|
||||
required ="true"
|
||||
requiredMessage="Name cannot be empty!"
|
||||
value="#{administratorManager.nameAdmin}">
|
||||
value="#{administratorManager.currentUser.name}">
|
||||
</h:inputText>
|
||||
<h:message for="name" />
|
||||
<h:outputLabel for="email" value="Email: "/>
|
||||
|
@ -29,7 +29,7 @@ and open the template in the editor.
|
|||
id="email"
|
||||
required ="true"
|
||||
requiredMessage="Email cannot be empty!"
|
||||
value="#{administratorManager.emailAdmin}">
|
||||
value="#{administratorManager.currentUser.email}">
|
||||
<f:validateRegex pattern="[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
|
||||
</h:inputText>
|
||||
<h:message for="email" />
|
||||
|
@ -38,7 +38,7 @@ and open the template in the editor.
|
|||
id="password"
|
||||
required ="true"
|
||||
requiredMessage="Password cannot be empty!"
|
||||
value="#{administratorManager.passwordAdmin}">
|
||||
value="#{administratorManager.currentUser.password}">
|
||||
</h:inputSecret>
|
||||
<h:message for="password" />
|
||||
</h:panelGrid>
|
||||
|
@ -46,7 +46,7 @@ and open the template in the editor.
|
|||
<h:commandButton
|
||||
id="submit"
|
||||
value="Submit"
|
||||
action="#{administratorManager.createAdmin}">
|
||||
action="#{administratorManager.updateAdmin}">
|
||||
</h:commandButton>
|
||||
<h:message for="submit" />
|
||||
</h:panelGrid>
|
||||
|
|
|
@ -15,7 +15,7 @@ and open the template in the editor.
|
|||
|
||||
<h:body>
|
||||
|
||||
<div>Events Management</div>
|
||||
<div>User management</div>
|
||||
|
||||
<h:dataTable value="#{administratorManager.getAllUsers()}" var="user">
|
||||
<h:column>
|
||||
|
@ -28,11 +28,29 @@ and open the template in the editor.
|
|||
<h:outputText value="#{user.email}"/>
|
||||
|
||||
</h:column>
|
||||
|
||||
<h:column>
|
||||
<f:facet name="header">
|
||||
<h:outputText value="Actions" />
|
||||
</f:facet>
|
||||
<h:form>
|
||||
<h:commandLink value="Update" action="admin_update_user?faces-redirect=true">
|
||||
<f:setPropertyActionListener target="#{administratorManager.currentUser}" value="#{user}" />
|
||||
</h:commandLink>
|
||||
|
||||
<h:commandLink value="Remove" actionListener="#{administratorManager.removeUser}">
|
||||
<f:param name="deleteStudentId" id="deleteUser" value="#{user.id}" />
|
||||
</h:commandLink>
|
||||
</h:form>
|
||||
</h:column>
|
||||
</h:dataTable>
|
||||
|
||||
<h:form>
|
||||
<h:commandLink action="admin_create_user" value="New User"></h:commandLink>
|
||||
|
||||
</h:form>
|
||||
|
||||
|
||||
<div>Events Management</div>
|
||||
</h:body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue