KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > faces > taglib > SelectItemTag


1 /*
2  * Copyright 1999-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.cocoon.faces.taglib;
17
18 import org.apache.cocoon.faces.FacesUtils;
19 import org.apache.commons.lang.BooleanUtils;
20
21 import javax.faces.FacesException;
22 import javax.faces.component.UIComponent;
23 import javax.faces.component.UISelectItem;
24
25 /**
26  * @version CVS $Id: SelectItemTag.java 46253 2004-09-17 14:36:29Z vgritsenko $
27  */

28 public class SelectItemTag extends UIComponentTag {
29
30     protected String JavaDoc value;
31     protected String JavaDoc itemValue;
32     protected String JavaDoc itemLabel;
33     protected String JavaDoc itemDescription;
34     protected String JavaDoc itemDisabled;
35
36     public void setValue(String JavaDoc value) {
37         this.value = value;
38     }
39
40     public void setItemValue(String JavaDoc itemValue) {
41         this.itemValue = itemValue;
42     }
43
44     public void setItemLabel(String JavaDoc itemLabel) {
45         this.itemLabel = itemLabel;
46     }
47
48     public void setItemDescription(String JavaDoc itemDescription) {
49         this.itemDescription = itemDescription;
50     }
51
52     public void setItemDisabled(String JavaDoc itemDisabled) {
53         this.itemDisabled = itemDisabled;
54     }
55
56     protected String JavaDoc getComponentType() {
57         return "javax.faces.SelectItem";
58     }
59
60     protected String JavaDoc getRendererType() {
61         return null;
62     }
63
64     protected void setProperties(UIComponent component) {
65         super.setProperties(component);
66
67         UISelectItem selectItem;
68         try {
69             selectItem = (UISelectItem) component;
70         } catch (ClassCastException JavaDoc cce) {
71             throw new FacesException("Tag <" + getClass().getName() + "> expected UISelectItem. " +
72                                      "Got <" + component.getClass().getName() + ">");
73         }
74
75         if (value != null) {
76             if (FacesUtils.isExpression(value)) {
77                 selectItem.setValueBinding("value", createValueBinding(value));
78             } else {
79                 selectItem.setValue(value);
80             }
81         }
82
83         if (itemValue != null) {
84             if (FacesUtils.isExpression(itemValue)) {
85                 selectItem.setValueBinding("itemValue", createValueBinding(itemValue));
86             } else {
87                 selectItem.setItemValue(itemValue);
88             }
89         }
90
91         if (itemLabel != null) {
92             if (FacesUtils.isExpression(itemLabel)) {
93                 selectItem.setValueBinding("itemLabel", createValueBinding(itemLabel));
94             } else {
95                 selectItem.setItemLabel(itemLabel);
96             }
97         }
98
99         if (itemDescription != null) {
100             if (FacesUtils.isExpression(itemDescription)) {
101                 selectItem.setValueBinding("itemDescription", createValueBinding(itemDescription));
102             } else {
103                 selectItem.setItemDescription(itemDescription);
104             }
105         }
106
107         if (itemDisabled != null) {
108             if (FacesUtils.isExpression(itemDisabled)) {
109                 selectItem.setValueBinding("itemDisabled", createValueBinding(itemDisabled));
110             } else {
111                 selectItem.setItemDisabled(BooleanUtils.toBoolean(itemDisabled));
112             }
113         }
114     }
115
116     public void recycle() {
117         super.recycle();
118         this.value = null;
119         this.itemValue = null;
120         this.itemLabel = null;
121         this.itemDescription = null;
122         this.itemDisabled = null;
123     }
124 }
125
Popular Tags