KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > j2ee > blueprints > web > CommandSubmissionsBean


1 /* Copyright 2004 Sun Microsystems, Inc. All rights reserved. You may not modify, use, reproduce, or distribute this software except in compliance with the terms of the License at:
2  http://developer.sun.com/berkeley_license.html
3  $Id: CommandSubmissionsBean.java,v 1.6 2005/03/26 10:06:43 inder Exp $ */

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 /**
14  * Backing bean for the command submission application
15  * @author Inderjeet Singh
16  */

17 public class CommandSubmissionsBean {
18     
19     private static final String JavaDoc SUCCESS = "success";
20     private static final String JavaDoc FAILURE = "failure";
21     private static final String JavaDoc AUTHORISED_USER = "Authorised User";
22     private static final String JavaDoc GUEST_USER = "Guest User";
23     
24     public CommandSubmissionsBean() {}
25     
26     /** matching property for the commandsubmissions:userName input field */
27     public void setUserName(String JavaDoc userName) {
28         this.userName = userName;
29     }
30     public String JavaDoc getUserName() {
31         return userName;
32     }
33     private String JavaDoc userName = null;
34     
35     /** matching property for the commandsubmissions:password input field */
36     public void setPassword(String JavaDoc password) {
37         this.password = password;
38     }
39     public String JavaDoc getPassword() {
40         return password;
41     }
42     private String JavaDoc password = null;
43     
44     /** matching property for the commandsubmissions:allowedUserName input field */
45     public void setAllowedUserName(String JavaDoc allowedUserName) {
46         this.allowedUserName = allowedUserName;
47     }
48     public String JavaDoc getAllowedUserName() {
49         return allowedUserName;
50     }
51     private String JavaDoc allowedUserName = null;
52     
53     /** matching property for the commandsubmissions:allowedPassword input field */
54     public void setAllowedPassword(String JavaDoc allowedPassword) {
55         this.allowedPassword = allowedPassword;
56     }
57     public String JavaDoc getAllowedPassword() {
58         return allowedPassword;
59     }
60     private String JavaDoc allowedPassword = null;
61     
62     /** matching property for the commandsubmissions:authStatus input field */
63     public void setAuthStatus(String JavaDoc authStatus) {
64         this.authStatus = authStatus;
65     }
66     public String JavaDoc getAuthStatus() {
67         return authStatus;
68     }
69     private String JavaDoc authStatus = null;
70     
71     public void setAuthType(String JavaDoc authType) {
72         this.authType = authType;
73     }
74     public String JavaDoc getAuthType() {
75         return authType;
76     }
77     private String JavaDoc authType = null;
78     
79     public String JavaDoc login() {
80         String JavaDoc 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     /** This action listener method is called by JSF when the
92      * "Show More Details/Hide Details" button is pressed */

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 JavaDoc value = (String JavaDoc) 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 JavaDoc("Unexpected value for button");
112         }
113     }
114 }
115
116
Popular Tags