|
| 1 | +/* |
| 2 | + * To change this template, choose Tools | Templates |
| 3 | + * and open the template in the editor. |
| 4 | + */ |
| 5 | +package com.baeldung.springintegration.controllers; |
| 6 | + |
| 7 | +import com.baeldung.springintegration.dao.IUserManagementDAO; |
| 8 | + |
| 9 | +import javax.faces.bean.ManagedBean; |
| 10 | +import javax.faces.bean.ManagedProperty; |
| 11 | +import javax.faces.bean.ViewScoped; |
| 12 | +import javax.faces.context.FacesContext; |
| 13 | +import java.io.Serializable; |
| 14 | +import java.util.logging.Logger; |
| 15 | + |
| 16 | +/** |
| 17 | + * |
| 18 | + * @author Tayo |
| 19 | + */ |
| 20 | +@ManagedBean(name = "registration") |
| 21 | +@ViewScoped |
| 22 | +public class RegistrationBean implements Serializable { |
| 23 | + |
| 24 | + @ManagedProperty(value = "#{userManagementDAO}") |
| 25 | + transient private IUserManagementDAO theUserDao; |
| 26 | + private String userName; |
| 27 | + private String operationMessage; |
| 28 | + private boolean operationStatus; |
| 29 | + |
| 30 | + /** |
| 31 | + * Creates a new instance of RegistrationBean |
| 32 | + */ |
| 33 | + public RegistrationBean() { |
| 34 | + } |
| 35 | + |
| 36 | + public String createNewUser() { |
| 37 | + try { |
| 38 | + Logger.getAnonymousLogger().info("Creating new user"); |
| 39 | + FacesContext context = FacesContext.getCurrentInstance(); |
| 40 | + operationStatus = theUserDao.createUser(userName); //DAO layer is used to register user using gathered data |
| 41 | + context.isValidationFailed(); |
| 42 | + if (operationStatus) { |
| 43 | + |
| 44 | + operationMessage = "User " + userName + " created"; |
| 45 | + } |
| 46 | + } catch (Exception ex) { |
| 47 | + Logger.getAnonymousLogger().severe("Error registering new user "); |
| 48 | + ex.printStackTrace(); |
| 49 | + } |
| 50 | + return null; |
| 51 | + } |
| 52 | + |
| 53 | + public String returnHome() { |
| 54 | + return "home"; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * @return the name |
| 59 | + */ |
| 60 | + public String getUserName() { |
| 61 | + return userName; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @param userName the name to set |
| 66 | + */ |
| 67 | + public void setUserName(String userName) { |
| 68 | + this.userName = userName; |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @param theUserDao the theUserDao to set |
| 73 | + */ |
| 74 | + public void setTheUserDao(IUserManagementDAO theUserDao) { |
| 75 | + this.theUserDao = theUserDao; |
| 76 | + } |
| 77 | + |
| 78 | + public IUserManagementDAO getTheUserDao() { |
| 79 | + return this.theUserDao; |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * @return the operationMessage |
| 84 | + */ |
| 85 | + public String getOperationMessage() { |
| 86 | + return operationMessage; |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * @param operationMessage the operationMessage to set |
| 91 | + */ |
| 92 | + public void setOperationMessage(String operationMessage) { |
| 93 | + this.operationMessage = operationMessage; |
| 94 | + } |
| 95 | +} |
0 commit comments