1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts.faces.component;
23
24
25 import javax.faces.component.UIOutput;
26 import javax.faces.context.FacesContext;
27 import javax.faces.el.ValueBinding;
28
29
30 /**
31 * <p>Custom component that replaces the Struts
32 * <code><html:errors></code> tag.</p>
33 */
34
35 public class ErrorsComponent extends UIOutput {
36
37
38
39
40
41 /**
42 * <p>Create a new {@link ErrorsComponent} with default properties.</p>
43 */
44 public ErrorsComponent() {
45
46 super();
47 setRendererType("org.apache.struts.faces.Errors");
48
49 }
50
51
52
53
54
55 /**
56 * <p>MessageResources attribute key to use for message lookup.</p>
57 */
58 private String bundle = null;
59
60
61 /**
62 * <p>Property name of the property to report errors for.</p>
63 */
64 private String property = null;
65
66
67
68
69
70 /**
71 * <p>Return the MessageResources key.</p>
72 */
73 public String getBundle() {
74
75 ValueBinding vb = getValueBinding("bundle");
76 if (vb != null) {
77 return (String) vb.getValue(getFacesContext());
78 } else {
79 return bundle;
80 }
81
82 }
83
84
85 /**
86 * <p>Set the MessageResources key.</p>
87 *
88 * @param bundle The new key
89 */
90 public void setBundle(String bundle) {
91
92 this.bundle = bundle;
93
94 }
95
96
97 /**
98 * <p>Return the component family to which this component belongs.</p>
99 */
100 public String getFamily() {
101
102 return "org.apache.struts.faces.Errors";
103
104 }
105
106
107 /**
108 * <p>Return the property name for which to report errors.</p>
109 */
110 public String getProperty() {
111
112 ValueBinding vb = getValueBinding("property");
113 if (vb != null) {
114 return (String) vb.getValue(getFacesContext());
115 } else {
116 return property;
117 }
118
119 }
120
121
122 /**
123 * <p>Set the property name for which to report errors.</p>
124 *
125 * @param property The new property name
126 */
127 public void setProperty(String property) {
128
129 this.property = property;
130
131 }
132
133
134
135
136
137 /**
138 * <p>Restore the state of this component.</p>
139 *
140 * @param context <code>FacesContext</code> for the current request
141 * @param state State object from which to restore our state
142 */
143 public void restoreState(FacesContext context, Object state) {
144
145 Object values[] = (Object[]) state;
146 super.restoreState(context, values[0]);
147 bundle = (String) values[1];
148 property = (String) values[2];
149
150 }
151
152
153 /**
154 * <p>Save the state of this component.</p>
155 *
156 * @param context <code>FacesContext</code> for the current request
157 */
158 public Object saveState(FacesContext context) {
159
160 Object values[] = new Object[3];
161 values[0] = super.saveState(context);
162 values[1] = bundle;
163 values[2] = property;
164 return values;
165
166 }
167
168
169 }