KickJava   Java API By Example, From Geeks To Geeks.

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


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.UIMessages;
25
26 /**
27  * @version CVS $Id: MessagesTag.java 55441 2004-10-24 16:14:10Z cziegeler $
28  */

29 public class MessagesTag extends UIComponentTag {
30
31     private String JavaDoc globalOnly;
32     private String JavaDoc showDetail;
33     private String JavaDoc showSummary;
34     private String JavaDoc errorClass;
35     private String JavaDoc errorStyle;
36     private String JavaDoc fatalClass;
37     private String JavaDoc fatalStyle;
38     private String JavaDoc infoClass;
39     private String JavaDoc infoStyle;
40     private String JavaDoc layout;
41     private String JavaDoc style;
42     private String JavaDoc styleClass;
43     private String JavaDoc title;
44     private String JavaDoc tooltip;
45     private String JavaDoc warnClass;
46     private String JavaDoc warnStyle;
47
48
49     public void setGlobalOnly(String JavaDoc globalOnly) {
50         this.globalOnly = globalOnly;
51     }
52
53     public void setShowDetail(String JavaDoc showDetail) {
54         this.showDetail = showDetail;
55     }
56
57     public void setShowSummary(String JavaDoc showSummary) {
58         this.showSummary = showSummary;
59     }
60
61     public void setErrorClass(String JavaDoc errorClass) {
62         this.errorClass = errorClass;
63     }
64
65     public void setErrorStyle(String JavaDoc errorStyle) {
66         this.errorStyle = errorStyle;
67     }
68
69     public void setFatalClass(String JavaDoc fatalClass) {
70         this.fatalClass = fatalClass;
71     }
72
73     public void setFatalStyle(String JavaDoc fatalStyle) {
74         this.fatalStyle = fatalStyle;
75     }
76
77     public void setInfoClass(String JavaDoc infoClass) {
78         this.infoClass = infoClass;
79     }
80
81     public void setInfoStyle(String JavaDoc infoStyle) {
82         this.infoStyle = infoStyle;
83     }
84
85     public void setLayout(String JavaDoc layout) {
86         this.layout = layout;
87     }
88
89     public void setStyle(String JavaDoc style) {
90         this.style = style;
91     }
92
93     public void setStyleClass(String JavaDoc styleClass) {
94         this.styleClass = styleClass;
95     }
96
97     public void setTitle(String JavaDoc title) {
98         this.title = title;
99     }
100
101     public void setTooltip(String JavaDoc tooltip) {
102         this.tooltip = tooltip;
103     }
104
105     public void setWarnClass(String JavaDoc warnClass) {
106         this.warnClass = warnClass;
107     }
108
109     public void setWarnStyle(String JavaDoc warnStyle) {
110         this.warnStyle = warnStyle;
111     }
112
113
114     public String JavaDoc getRendererType() {
115         return "javax.faces.Messages";
116     }
117
118     public String JavaDoc getComponentType() {
119         return "javax.faces.HtmlMessages";
120     }
121
122
123     protected void setProperties(UIComponent component) {
124         super.setProperties(component);
125
126         UIMessages messages = null;
127         try {
128             messages = (UIMessages) component;
129         } catch (ClassCastException JavaDoc cce) {
130             throw new FacesException("Tag <" + getClass().getName() + "> expected UIMessages. " +
131                                      "Got <" + component.getClass().getName() + ">");
132         }
133
134         if (globalOnly != null) {
135             if (FacesUtils.isExpression(globalOnly)) {
136                 messages.setValueBinding("globalOnly", createValueBinding(globalOnly));
137             } else {
138                 messages.setGlobalOnly(BooleanUtils.toBoolean(globalOnly));
139             }
140         }
141
142         if (showDetail != null) {
143             if (FacesUtils.isExpression(showDetail)) {
144                 messages.setValueBinding("showDetail", createValueBinding(showDetail));
145             } else {
146                 messages.setShowDetail(BooleanUtils.toBoolean(showDetail));
147             }
148         }
149
150         if (showSummary != null) {
151             if (FacesUtils.isExpression(showSummary)) {
152                 messages.setValueBinding("showSummary", createValueBinding(showSummary));
153             } else {
154                 messages.setShowSummary(BooleanUtils.toBoolean(showSummary));
155             }
156         }
157
158         setProperty(component, "errorClass", errorClass);
159         setProperty(component, "errorStyle", errorStyle);
160         setProperty(component, "fatalClass", fatalClass);
161         setProperty(component, "fatalStyle", fatalStyle);
162         setProperty(component, "infoClass", infoClass);
163         setProperty(component, "infoStyle", infoStyle);
164         setProperty(component, "layout", layout);
165         setProperty(component, "style", style);
166         setProperty(component, "styleClass", styleClass);
167         setProperty(component, "title", title);
168
169         setBooleanProperty(component, "tooltip", tooltip);
170
171         setProperty(component, "warnClass", warnClass);
172         setProperty(component, "warnStyle", warnStyle);
173     }
174
175     public void recycle() {
176         super.recycle();
177         globalOnly = null;
178         showDetail = null;
179         showSummary = null;
180         errorClass = null;
181         errorStyle = null;
182         fatalClass = null;
183         fatalStyle = null;
184         infoClass = null;
185         infoStyle = null;
186         layout = null;
187         style = null;
188         styleClass = null;
189         title = null;
190         tooltip = null;
191         warnClass = null;
192         warnStyle = null;
193     }
194 }
195
Popular Tags