KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > component > html > ext > HtmlCommandButton


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.component.html.ext;
17
18 import org.apache.myfaces.component.UserRoleAware;
19 import org.apache.myfaces.component.UserRoleUtils;
20 import org.apache.myfaces.component.html.util.HtmlComponentUtils;
21
22 import javax.faces.context.FacesContext;
23 import javax.faces.el.ValueBinding;
24
25 /**
26  * @author Manfred Geiler (latest modification by $Author: matzew $)
27  * @version $Revision: 1.5 $ $Date: 2005/01/16 20:09:53 $
28  * $Log: HtmlCommandButton.java,v $
29  * Revision 1.5 2005/01/16 20:09:53 matzew
30  * added patch form Sean Schofield. forceId for reuse of "legacy JavaScript" (MyFaces-70)
31  *
32  * Revision 1.4 2004/10/13 11:50:56 matze
33  * renamed packages to org.apache
34  *
35  * Revision 1.3 2004/07/01 21:53:05 mwessendorf
36  * ASF switch
37  *
38  * Revision 1.2 2004/05/18 14:31:36 manolito
39  * user role support completely moved to components source tree
40  *
41  * Revision 1.1 2004/04/01 09:23:12 manolito
42  * more extended components
43  *
44  */

45 public class HtmlCommandButton
46         extends javax.faces.component.html.HtmlCommandButton
47         implements UserRoleAware
48 {
49
50     public String JavaDoc getClientId(FacesContext context)
51     {
52         String JavaDoc clientId = HtmlComponentUtils.getClientId(this, getRenderer(context), context);
53         if (clientId == null)
54         {
55             clientId = super.getClientId(context);
56         }
57
58         return clientId;
59     }
60     
61     //------------------ GENERATED CODE BEGIN (do not modify!) --------------------
62

63     public static final String JavaDoc COMPONENT_TYPE = "org.apache.myfaces.HtmlCommandButton";
64
65     private String JavaDoc _enabledOnUserRole = null;
66     private String JavaDoc _visibleOnUserRole = null;
67
68     public HtmlCommandButton()
69     {
70     }
71
72
73     public void setEnabledOnUserRole(String JavaDoc enabledOnUserRole)
74     {
75         _enabledOnUserRole = enabledOnUserRole;
76     }
77
78     public String JavaDoc getEnabledOnUserRole()
79     {
80         if (_enabledOnUserRole != null) return _enabledOnUserRole;
81         ValueBinding vb = getValueBinding("enabledOnUserRole");
82         return vb != null ? (String JavaDoc)vb.getValue(getFacesContext()) : null;
83     }
84
85     public void setVisibleOnUserRole(String JavaDoc visibleOnUserRole)
86     {
87         _visibleOnUserRole = visibleOnUserRole;
88     }
89
90     public String JavaDoc getVisibleOnUserRole()
91     {
92         if (_visibleOnUserRole != null) return _visibleOnUserRole;
93         ValueBinding vb = getValueBinding("visibleOnUserRole");
94         return vb != null ? (String JavaDoc)vb.getValue(getFacesContext()) : null;
95     }
96
97
98     public boolean isRendered()
99     {
100         if (!UserRoleUtils.isVisibleOnUserRole(this)) return false;
101         return super.isRendered();
102     }
103
104     public Object JavaDoc saveState(FacesContext context)
105     {
106         Object JavaDoc values[] = new Object JavaDoc[3];
107         values[0] = super.saveState(context);
108         values[1] = _enabledOnUserRole;
109         values[2] = _visibleOnUserRole;
110         return ((Object JavaDoc) (values));
111     }
112
113     public void restoreState(FacesContext context, Object JavaDoc state)
114     {
115         Object JavaDoc values[] = (Object JavaDoc[])state;
116         super.restoreState(context, values[0]);
117         _enabledOnUserRole = (String JavaDoc)values[1];
118         _visibleOnUserRole = (String JavaDoc)values[2];
119     }
120     //------------------ GENERATED CODE END ---------------------------------------
121
}
122
Popular Tags