KickJava   Java API By Example, From Geeks To Geeks.

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


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.ActionSource;
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 import javax.faces.event.ActionEvent;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 /**
29  * Implements attributes:
30  * <ol>
31  * <li>action
32  * <li>actionListener
33  * </ol>
34  *
35  * @author <a HREF="mailto:Jiri.Zaloudek@ivancice.cz">Jiri Zaloudek</a> (latest modification by $Author: matzew $)
36  * @version $Revision: 1.1 $ $Date: 2004/12/30 09:37:27 $
37  * $Log: ActionSourceTagBase.java,v $
38  * Revision 1.1 2004/12/30 09:37:27 matzew
39  * added a new RenderKit for WML. Thanks to Jirí Žaloudek
40  *
41  */

42 public abstract class ActionSourceTagBase extends ComponentTagBase {
43     private static Log log = LogFactory.getLog(ActionSourceTagBase.class);
44     
45     /* properties */
46     private String JavaDoc action = null;
47     private String JavaDoc actionListener = null;
48     private String JavaDoc immediate = null;
49     
50     /** Creates a new instance of CommandTag */
51     public ActionSourceTagBase() {
52         super();
53     }
54     
55     public abstract String JavaDoc getRendererType();
56     
57     public void release() {
58         super.release();
59         this.action = null;
60         this.actionListener = null;
61         this.immediate = null;
62     }
63     
64     protected void setProperties(UIComponent component) {
65         super.setProperties(component);
66         
67         Class JavaDoc[] mbParams = {ActionEvent.class};
68         
69         if (action != null) {
70             if (!(component instanceof ActionSource)) {
71                 throw new IllegalArgumentException JavaDoc("Component " + component.getId() + " is no ActionSource, cannot set 'action' attribute.");
72             }
73             MethodBinding mb;
74             if (isValueReference(action))
75                 mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding(action, null);
76             else
77                 mb = new ConstantMethodBinding(action);
78             
79             ((ActionSource)component).setAction(mb);
80         }
81         
82         if (actionListener != null) {
83             if (!(component instanceof ActionSource)) {
84                 throw new IllegalArgumentException JavaDoc("Component " + component.getId() + " is no ActionSource, cannot set 'actionListener' attribute.");
85             }
86             if (isValueReference(actionListener)) {
87                 MethodBinding mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding(actionListener, mbParams);
88                 ((ActionSource)component).setActionListener(mb);
89             }
90             else {
91                 log.error("Invalid expression " + actionListener);
92             }
93         }
94         
95         if (immediate != null) {
96             if (component instanceof ActionSource) {
97                 if (isValueReference(immediate)) {
98                     ValueBinding vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(immediate);
99                     component.setValueBinding("immediate", vb);
100                 }
101                 else {
102                     Boolean JavaDoc imm = Boolean.valueOf(immediate);
103                     ((ActionSource)component).setImmediate(imm.booleanValue());
104                 }
105                 
106             }
107             else log.error("Component " + component.getClass().getName() + " is no ActionSource, cannot set 'immediate' attribute.");
108         }
109     }
110     
111     // ----------------------------------------------------- Getters and Setters
112
public String JavaDoc getAction() {
113         return action;
114     }
115     
116     public void setAction(String JavaDoc action) {
117         this.action = action;
118     }
119     
120     public String JavaDoc getActionListener() {
121         return actionListener;
122     }
123     
124     public void setActionListener(String JavaDoc actionListener) {
125         this.actionListener = actionListener;
126     }
127     
128     /**
129      * Getter for property immediate.
130      * @return value of property immediate.
131      */

132     public String JavaDoc getImmediate() {
133         return immediate;
134     }
135     
136     /**
137      * Setter for property immediate.
138      * @param converter new value of property immediate.
139      */

140     public void setImmediate(String JavaDoc immediate) {
141         this.immediate = immediate;
142     }
143 }
144
Popular Tags