KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > faces > component > ErrorsComponent


1 /*
2  * Copyright 2002-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
17 package org.apache.struts.faces.component;
18
19
20 import javax.faces.component.UIOutput;
21 import javax.faces.context.FacesContext;
22 import javax.faces.el.ValueBinding;
23
24
25 /**
26  * <p>Custom component that replaces the Struts
27  * <code>&lt;html:errors&gt;</code> tag.</p>
28  */

29
30 public class ErrorsComponent extends UIOutput {
31
32
33     // ------------------------------------------------------------ Constructors
34

35
36     /**
37      * <p>Create a new {@link ErrorsComponent} with default properties.</p>
38      */

39     public ErrorsComponent() {
40
41         super();
42         setRendererType("org.apache.struts.faces.Errors");
43
44     }
45
46
47     // ------------------------------------------------------ Instance Variables
48

49
50     /**
51      * <p>MessageResources attribute key to use for message lookup.</p>
52      */

53     private String JavaDoc bundle = null;
54
55
56     /**
57      * <p>Property name of the property to report errors for.</p>
58      */

59     private String JavaDoc property = null;
60
61
62     // ---------------------------------------------------- Component Properties
63

64
65     /**
66      * <p>Return the MessageResources key.</p>
67      */

68     public String JavaDoc getBundle() {
69
70         ValueBinding vb = getValueBinding("bundle");
71         if (vb != null) {
72             return (String JavaDoc) vb.getValue(getFacesContext());
73         } else {
74             return bundle;
75         }
76
77     }
78
79
80     /**
81      * <p>Set the MessageResources key.</p>
82      *
83      * @param bundle The new key
84      */

85     public void setBundle(String JavaDoc bundle) {
86
87         this.bundle = bundle;
88
89     }
90
91
92     /**
93      * <p>Return the component family to which this component belongs.</p>
94      */

95     public String JavaDoc getFamily() {
96
97         return "org.apache.struts.faces.Errors";
98
99     }
100
101
102     /**
103      * <p>Return the property name for which to report errors.</p>
104      */

105     public String JavaDoc getProperty() {
106
107         ValueBinding vb = getValueBinding("property");
108         if (vb != null) {
109             return (String JavaDoc) vb.getValue(getFacesContext());
110         } else {
111             return property;
112         }
113
114     }
115
116
117     /**
118      * <p>Set the property name for which to report errors.</p>
119      *
120      * @param property The new property name
121      */

122     public void setProperty(String JavaDoc property) {
123
124         this.property = property;
125
126     }
127
128
129     // ---------------------------------------------------- StateManager Methods
130

131
132     /**
133      * <p>Restore the state of this component.</p>
134      *
135      * @param context <code>FacesContext</code> for the current request
136      * @param state State object from which to restore our state
137      */

138     public void restoreState(FacesContext context, Object JavaDoc state) {
139
140         Object JavaDoc values[] = (Object JavaDoc[]) state;
141         super.restoreState(context, values[0]);
142         bundle = (String JavaDoc) values[1];
143         property = (String JavaDoc) values[2];
144
145     }
146
147
148     /**
149      * <p>Save the state of this component.</p>
150      *
151      * @param context <code>FacesContext</code> for the current request
152      */

153     public Object JavaDoc saveState(FacesContext context) {
154
155         Object JavaDoc values[] = new Object JavaDoc[3];
156         values[0] = super.saveState(context);
157         values[1] = bundle;
158         values[2] = property;
159         return values;
160
161     }
162
163
164 }
165
Popular Tags