1 4 5 package com.sun.j2ee.blueprints.web; 6 7 import javax.faces.component.UIComponent; 8 import javax.faces.context.FacesContext; 9 import javax.faces.application.FacesMessage; 10 import javax.faces.validator.ValidatorException; 11 import javax.faces.event.*; 12 13 17 public class CommandSubmissionsBean { 18 19 private static final String SUCCESS = "success"; 20 private static final String FAILURE = "failure"; 21 private static final String AUTHORISED_USER = "Authorised User"; 22 private static final String GUEST_USER = "Guest User"; 23 24 public CommandSubmissionsBean() {} 25 26 27 public void setUserName(String userName) { 28 this.userName = userName; 29 } 30 public String getUserName() { 31 return userName; 32 } 33 private String userName = null; 34 35 36 public void setPassword(String password) { 37 this.password = password; 38 } 39 public String getPassword() { 40 return password; 41 } 42 private String password = null; 43 44 45 public void setAllowedUserName(String allowedUserName) { 46 this.allowedUserName = allowedUserName; 47 } 48 public String getAllowedUserName() { 49 return allowedUserName; 50 } 51 private String allowedUserName = null; 52 53 54 public void setAllowedPassword(String allowedPassword) { 55 this.allowedPassword = allowedPassword; 56 } 57 public String getAllowedPassword() { 58 return allowedPassword; 59 } 60 private String allowedPassword = null; 61 62 63 public void setAuthStatus(String authStatus) { 64 this.authStatus = authStatus; 65 } 66 public String getAuthStatus() { 67 return authStatus; 68 } 69 private String authStatus = null; 70 71 public void setAuthType(String authType) { 72 this.authType = authType; 73 } 74 public String getAuthType() { 75 return authType; 76 } 77 private String authType = null; 78 79 public String login() { 80 String outcome = getUserName().equals(getAllowedUserName()) && getPassword().equals(getAllowedPassword()) ? SUCCESS : FAILURE; 81 if (outcome.equals(SUCCESS)) { 82 authStatus = "Login Succeeded"; 83 authType = AUTHORISED_USER; 84 } else { 85 authStatus = "Login Failed"; 86 authType = GUEST_USER; 87 } 88 return outcome; 89 } 90 91 93 public void detailsActionListener(ActionEvent ae) { 94 UIComponent src = ae.getComponent(); 95 UIComponent addrText = src.findComponent("commandsubmissions:addressText"); 96 UIComponent addrTextArea = src.findComponent("commandsubmissions:addressTextArea"); 97 String value = (String ) src.getAttributes().get("value"); 98 if (value.equals("Show More Details")) { 99 src.getAttributes().put("value", "Hide Details"); 100 if (addrText != null) 101 addrText.setRendered(true); 102 if (addrTextArea != null) 103 addrTextArea.setRendered(true); 104 } else if (value.equals("Hide Details")) { 105 if (addrText != null) 106 addrText.setRendered(false); 107 if (addrTextArea != null) 108 addrTextArea.setRendered(false); 109 src.getAttributes().put("value", "Show More Details"); 110 } else { 111 throw new RuntimeException ("Unexpected value for button"); 112 } 113 } 114 } 115 116 | Popular Tags |