KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > custom > checkbox > HtmlCheckbox


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.custom.checkbox;
17
18 import javax.faces.component.UIComponentBase;
19 import javax.faces.context.FacesContext;
20 import javax.faces.el.ValueBinding;
21
22 /**
23  * @author Manfred Geiler (latest modification by $Author: manolito $)
24  * @version $Revision: 1.4 $ $Date: 2005/04/13 12:48:46 $
25  * $Log: HtmlCheckbox.java,v $
26  * Revision 1.4 2005/04/13 12:48:46 manolito
27  * MYFACES-186 x:radio and x:checkbox cause ClassCastException
28  * Since the proposed fix is within generated code block, I had to fix the generator instead!
29  *
30  * Revision 1.3 2004/10/13 11:50:57 matze
31  * renamed packages to org.apache
32  *
33  * Revision 1.2 2004/07/01 21:53:06 mwessendorf
34  * ASF switch
35  *
36  * Revision 1.1 2004/04/02 13:57:10 manolito
37  * extended HtmlSelectManyCheckbox with layout "spread" and custom Checkbox component
38  *
39  */

40 public class HtmlCheckbox
41     extends UIComponentBase
42 {
43     //private static final Log log = LogFactory.getLog(HtmlRadio.class);
44

45     public static final String JavaDoc FOR_ATTR = "for".intern();
46     public static final String JavaDoc INDEX_ATTR = "index".intern();
47
48
49     //------------------ GENERATED CODE BEGIN (do not modify!) --------------------
50

51     public static final String JavaDoc COMPONENT_TYPE = "org.apache.myfaces.HtmlCheckbox";
52     public static final String JavaDoc COMPONENT_FAMILY = "org.apache.myfaces.Checkbox";
53     private static final String JavaDoc DEFAULT_RENDERER_TYPE = "org.apache.myfaces.Checkbox";
54
55     private String JavaDoc _for = null;
56     private Integer JavaDoc _index = null;
57
58     public HtmlCheckbox()
59     {
60         setRendererType(DEFAULT_RENDERER_TYPE);
61     }
62
63     public String JavaDoc getFamily()
64     {
65         return COMPONENT_FAMILY;
66     }
67
68     public void setFor(String JavaDoc forValue)
69     {
70         _for = forValue;
71     }
72
73     public String JavaDoc getFor()
74     {
75         if (_for != null) return _for;
76         ValueBinding vb = getValueBinding("for");
77         return vb != null ? (String JavaDoc)vb.getValue(getFacesContext()) : null;
78     }
79
80     public void setIndex(int index)
81     {
82         _index = new Integer JavaDoc(index);
83     }
84
85     public int getIndex()
86     {
87         if (_index != null) return _index.intValue();
88         ValueBinding vb = getValueBinding("index");
89         Number JavaDoc v = vb != null ? (Number JavaDoc)vb.getValue(getFacesContext()) : null;
90         return v != null ? v.intValue() : Integer.MIN_VALUE;
91     }
92
93
94
95     public Object JavaDoc saveState(FacesContext context)
96     {
97         Object JavaDoc values[] = new Object JavaDoc[3];
98         values[0] = super.saveState(context);
99         values[1] = _for;
100         values[2] = _index;
101         return ((Object JavaDoc) (values));
102     }
103
104     public void restoreState(FacesContext context, Object JavaDoc state)
105     {
106         Object JavaDoc values[] = (Object JavaDoc[])state;
107         super.restoreState(context, values[0]);
108         _for = (String JavaDoc)values[1];
109         _index = (Integer JavaDoc)values[2];
110     }
111     //------------------ GENERATED CODE END ---------------------------------------
112

113 }
114
Popular Tags