KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > faces > taglib > html > InputHiddenTag


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.html;
17
18 import org.apache.cocoon.faces.FacesUtils;
19 import org.apache.cocoon.faces.taglib.UIComponentTag;
20 import org.apache.commons.lang.BooleanUtils;
21
22 import javax.faces.FacesException;
23 import javax.faces.component.UIComponent;
24 import javax.faces.component.UIInput;
25 import javax.faces.context.FacesContext;
26 import javax.faces.el.MethodBinding;
27 import javax.faces.event.ValueChangeEvent;
28
29 /**
30  * @version CVS $Id: InputHiddenTag.java 46253 2004-09-17 14:36:29Z vgritsenko $
31  */

32 public class InputHiddenTag extends UIComponentTag {
33
34     private String JavaDoc converter;
35     private String JavaDoc immediate;
36     private String JavaDoc required;
37     private String JavaDoc validator;
38     private String JavaDoc value;
39     private String JavaDoc valueChangeListener;
40
41
42     public void setConverter(String JavaDoc converter) {
43         this.converter = converter;
44     }
45
46     public void setImmediate(String JavaDoc immediate) {
47         this.immediate = immediate;
48     }
49
50     public void setRequired(String JavaDoc required) {
51         this.required = required;
52     }
53
54     public void setValidator(String JavaDoc validator) {
55         this.validator = validator;
56     }
57
58     public void setValue(String JavaDoc value) {
59         this.value = value;
60     }
61
62     public void setValueChangeListener(String JavaDoc valueChangeListener) {
63         this.valueChangeListener = valueChangeListener;
64     }
65
66
67     public String JavaDoc getRendererType() {
68         return "javax.faces.Hidden";
69     }
70
71     public String JavaDoc getComponentType() {
72         return "javax.faces.HtmlInputHidden";
73     }
74
75
76     protected void setProperties(UIComponent component) {
77         super.setProperties(component);
78
79         UIInput input = null;
80         try {
81             input = (UIInput) component;
82         } catch (ClassCastException JavaDoc cce) {
83             throw new FacesException("Tag <" + getClass().getName() + "> expected UIInput. " +
84                                      "Got <" + component.getClass().getName() + ">");
85         }
86
87         if (converter != null) {
88             if (FacesUtils.isExpression(converter)) {
89                 input.setValueBinding("converter", createValueBinding(converter));
90             } else {
91                 input.setConverter(getApplication().createConverter(converter));
92             }
93         }
94
95         if (immediate != null) {
96             if (FacesUtils.isExpression(immediate)) {
97                 input.setValueBinding("immediate", createValueBinding(immediate));
98             } else {
99                 input.setImmediate(BooleanUtils.toBoolean(immediate));
100             }
101         }
102
103         if (required != null) {
104             if (FacesUtils.isExpression(required)) {
105                 input.setValueBinding("required", createValueBinding(required));
106             } else {
107                 input.setRequired(BooleanUtils.toBoolean(required));
108             }
109         }
110
111         if (validator != null) {
112             if (FacesUtils.isExpression(validator)) {
113                 MethodBinding vb = getApplication().createMethodBinding(validator,
114                                                                         new Class JavaDoc[]{ FacesContext.class, UIComponent.class, Object JavaDoc.class });
115                 input.setValidator(vb);
116             } else {
117                 throw new FacesException("Tag <" + getClass().getName() + "> validator must be an expression. " +
118                                          "Got <" + validator + ">");
119             }
120         }
121
122         if (value != null) {
123             if (FacesUtils.isExpression(value)) {
124                 input.setValueBinding("value", createValueBinding(value));
125             } else {
126                 input.setValue(value);
127             }
128         }
129
130         if (valueChangeListener != null) {
131             if (FacesUtils.isExpression(valueChangeListener)) {
132                 MethodBinding vb = getApplication().createMethodBinding(valueChangeListener,
133                                                                         new Class JavaDoc[]{ ValueChangeEvent.class });
134                 input.setValueChangeListener(vb);
135             } else {
136                 throw new FacesException("Tag <" + getClass().getName() + "> valueChangeListener must be an expression. " +
137                                          "Got <" + valueChangeListener + ">");
138             }
139         }
140     }
141
142     public void recycle() {
143         super.recycle();
144         converter = null;
145         immediate = null;
146         required = null;
147         validator = null;
148         value = null;
149         valueChangeListener = null;
150     }
151 }
152
Popular Tags