KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > wap > base > ValueHolderTagBase


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.wap.base;
17
18 import javax.faces.component.UIComponent;
19 import javax.faces.component.ValueHolder;
20 import javax.faces.context.FacesContext;
21 import javax.faces.convert.Converter;
22 import javax.faces.el.ValueBinding;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 /**
28  * Implements attributes:
29  * <ol>
30  * <li>converter
31  * <li>value
32  * </ol>
33  *
34  * @author <a HREF="mailto:Jiri.Zaloudek@ivancice.cz">Jiri Zaloudek</a> (latest modification by $Author: matzew $)
35  * @version $Revision: 1.1 $ $Date: 2004/12/30 09:37:27 $
36  * $Log: ValueHolderTagBase.java,v $
37  * Revision 1.1 2004/12/30 09:37:27 matzew
38  * added a new RenderKit for WML. Thanks to Jirí Žaloudek
39  *
40  */

41 public abstract class ValueHolderTagBase extends ComponentTagBase {
42     private static Log log = LogFactory.getLog(ValueHolderTagBase.class);
43     
44     /* properties */
45     private String JavaDoc converter = null;
46     private String JavaDoc value = null;
47     
48     /** Creates a new instance of ValueTag */
49     public ValueHolderTagBase() {
50         super();
51     }
52     
53     public abstract String JavaDoc getRendererType();
54     
55     public void release() {
56         super.release();
57         this.converter = null;
58         this.value = null;
59     }
60     
61     protected void setProperties(UIComponent component) {
62         super.setProperties(component);
63         
64         if (converter != null) {
65             if (component instanceof ValueHolder) {
66                 if (isValueReference(converter)) {
67                     ValueBinding vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(converter);
68                     component.setValueBinding("converter", vb);
69                 }
70                 else {
71                     FacesContext facesContext = FacesContext.getCurrentInstance();
72                     Converter conv = facesContext.getApplication().createConverter(converter);
73                     ((ValueHolder)component).setConverter(conv);
74                 }
75             }
76             else {
77                 log.error("Component " + component.getClass().getName() + " is no ValueHolder, cannot set 'converter' attribute.");
78             }
79         }
80         
81         
82         if (value != null) {
83             if (component instanceof ValueHolder) {
84                 if (isValueReference(value)) {
85                     ValueBinding vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(value);
86                     component.setValueBinding("value", vb);
87                 } else
88                     ((ValueHolder)component).setValue(value);
89                 
90             }
91             else log.error("Component " + component.getClass().getName() + " is no ValueHolder, cannot set 'value' attribute.");
92         }
93         
94     }
95     // ----------------------------------------------------- Getters and Setters
96

97     /**
98      * Getter for property converter.
99      * @return value of property converter.
100      */

101     public String JavaDoc getConverter() {
102         return converter;
103     }
104     
105     /**
106      * Setter for property converter.
107      * @param converter new value of property converter.
108      */

109     public void setConverter(String JavaDoc converter) {
110         this.converter = converter;
111     }
112     
113     /**
114      * Getter for property value.
115      * @return value of property value.
116      */

117     public String JavaDoc getValue() {
118         return value;
119     }
120     
121     /**
122      * Setter for property value.
123      * @param value new value of property value.
124      */

125     public void setValue(String JavaDoc value) {
126         this.value = value;
127     }
128 }
129
Popular Tags