1
2
3
4
5
6
7
8
9
10
11
12
13
14
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><html:errors></code> tag.</p>
28 */
29
30 public class ErrorsComponent extends UIOutput {
31
32
33
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
48
49
50 /***
51 * <p>MessageResources attribute key to use for message lookup.</p>
52 */
53 private String bundle = null;
54
55
56 /***
57 * <p>Property name of the property to report errors for.</p>
58 */
59 private String property = null;
60
61
62
63
64
65 /***
66 * <p>Return the MessageResources key.</p>
67 */
68 public String getBundle() {
69
70 ValueBinding vb = getValueBinding("bundle");
71 if (vb != null) {
72 return (String) 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 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 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 getProperty() {
106
107 ValueBinding vb = getValueBinding("property");
108 if (vb != null) {
109 return (String) 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 property) {
123
124 this.property = property;
125
126 }
127
128
129
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 state) {
139
140 Object values[] = (Object[]) state;
141 super.restoreState(context, values[0]);
142 bundle = (String) values[1];
143 property = (String) 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 saveState(FacesContext context) {
154
155 Object values[] = new Object[3];
156 values[0] = super.saveState(context);
157 values[1] = bundle;
158 values[2] = property;
159 return values;
160
161 }
162
163
164 }