KickJava   Java API By Example, From Geeks To Geeks.

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


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.EditableValueHolder;
19 import javax.faces.component.UIComponent;
20 import javax.faces.context.FacesContext;
21 import javax.faces.el.MethodBinding;
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>immediate
31  * <li>required
32  * <li>validator
33  * <li>valueChangeListener
34  * </ol>
35  *
36  * @author <a HREF="mailto:Jiri.Zaloudek@ivancice.cz">Jiri Zaloudek</a> (latest modification by $Author: matzew $)
37  * @version $Revision: 1.1 $ $Date: 2004/12/30 09:37:27 $
38  * $Log: EditableValueHolderTagBase.java,v $
39  * Revision 1.1 2004/12/30 09:37:27 matzew
40  * added a new RenderKit for WML. Thanks to Jirí Žaloudek
41  *
42  */

43 public abstract class EditableValueHolderTagBase extends ValueHolderTagBase {
44     private static Log log = LogFactory.getLog(EditableValueHolderTagBase.class);
45     
46     /* properties */
47     private String JavaDoc immediate = null;
48     private String JavaDoc required = null;
49     private String JavaDoc validator = null;
50     private String JavaDoc valueChangeListener = null;
51     
52     /** Creates a new instance of UIComponentTagBase */
53     public EditableValueHolderTagBase() {
54         super();
55     }
56     
57     public abstract String JavaDoc getRendererType();
58     
59     public void release() {
60         super.release();
61         this.immediate = null;
62         this.required = null;
63         this.validator = null;
64         this.valueChangeListener = null;
65     }
66     
67     protected void setProperties(UIComponent component) {
68         super.setProperties(component);
69         
70         /* method binding parameters */
71         Class JavaDoc[] mbParams = {FacesContext.class, UIComponent.class, Object JavaDoc.class};
72         
73         if (immediate != null) {
74             if (component instanceof EditableValueHolder) {
75                 if (isValueReference(immediate)) {
76                     ValueBinding vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(immediate);
77                     component.setValueBinding("immediate", vb);
78                 }
79                 else {
80                     boolean imm = stringToBoolean(immediate);
81                     ((EditableValueHolder)component).setImmediate(imm);
82                 }
83                 
84             }
85             else log.error("Component " + component.getClass().getName() + " is no ValueHolder, cannot set 'immediate' attribute.");
86         }
87         
88         if (required != null) {
89             if (component instanceof EditableValueHolder) {
90                 if (isValueReference(required)) {
91                     ValueBinding vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(required);
92                     component.setValueBinding("required", vb);
93                 } else {
94                     boolean req = stringToBoolean(required);
95                     ((EditableValueHolder)component).setRequired(req);
96                 }
97             }
98             else {
99                 log.error("Component " + component.getClass().getName() + " is no EditableValueHolder, cannot set 'required'.");
100             }
101         }
102         
103         if (validator != null) {
104             if (component instanceof EditableValueHolder) {
105                 if (isValueReference(validator)) {
106                     Class JavaDoc[] params = {FacesContext.class, UIComponent.class, Object JavaDoc.class};
107                     
108                     FacesContext facesContext = FacesContext.getCurrentInstance();
109                     MethodBinding mb = facesContext.getApplication().createMethodBinding(validator, mbParams);
110                     ((EditableValueHolder)component).setValidator(mb);
111                 }
112                 else {
113                     log.error("Invalid expression " + validator);
114                 }
115             }
116             else {
117                 log.error("Component " + component.getClass().getName() + " is no EditableValueHolder, cannot set 'validator'.");
118             }
119         }
120         
121         if (valueChangeListener != null) {
122             if (component instanceof EditableValueHolder) {
123                 if (isValueReference(valueChangeListener)) {
124
125                     FacesContext facesContext = FacesContext.getCurrentInstance();
126                     MethodBinding mb = facesContext.getApplication().createMethodBinding(valueChangeListener, mbParams);
127                     ((EditableValueHolder)component).setValueChangeListener(mb);
128                 }
129                 else {
130                     log.error("Invalid expression " + valueChangeListener);
131                 }
132             }
133             else {
134                 log.error("Component " + component.getClass().getName() + " is no EditableValueHolder, cannot set 'valueChangedListener'.");
135             }
136         }
137     }
138     
139     private boolean stringToBoolean(String JavaDoc str){
140         Boolean JavaDoc bool = Boolean.valueOf(str);
141         return(bool.booleanValue());
142     }
143
144     // ----------------------------------------------------- Getters and Setters
145
/**
146      * Getter for property immediate.
147      * @return value of property immediate.
148      */

149     public String JavaDoc getImmediate() {
150         return immediate;
151     }
152     
153     /**
154      * Setter for property immediate.
155      * @param converter new value of property immediate.
156      */

157     public void setImmediate(String JavaDoc immediate) {
158         this.immediate = immediate;
159     }
160     
161     public String JavaDoc getRequired() {
162         return required;
163     }
164
165     public void setRequired(String JavaDoc required) {
166         this.required=required;
167     }
168
169     public String JavaDoc getValidator() {
170         return validator;
171     }
172
173     public void setValidator(String JavaDoc validator) {
174         this.validator=validator;
175     }
176
177     public String JavaDoc getValueChangeListener() {
178         return valueChangeListener;
179     }
180
181     public void setValueChangeListener(String JavaDoc valueChangeListener) {
182         this.valueChangeListener=valueChangeListener;
183     }
184     
185     
186 }
187
Popular Tags