2
* Copyright 2002-2004 The Apache Software Foundation.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
package org.apache.struts.faces.component;
20
import java.io.IOException;
21
import java.util.Iterator;
23
import javax.faces.component.UIOutput;
24
import javax.faces.context.FacesContext;
25
import javax.faces.el.ValueBinding;
29
* <p>Custom component that replaces the Struts
30
* <code><html:errors></code> tag.</p>
33
public class ErrorsComponent extends UIOutput {
36
// ------------------------------------------------------------ Constructors
40
* <p>Create a new {@link ErrorsComponent} with default properties.</p>
42
public ErrorsComponent() {
45
setRendererType("org.apache.struts.faces.Errors");
50
// ------------------------------------------------------ Instance Variables
54
* <p>MessageResources attribute key to use for message lookup.</p>
56
private String bundle = null;
60
* <p>Property name of the property to report errors for.</p>
62
private String property = null;
65
// ---------------------------------------------------- Component Properties
69
* <p>Return the MessageResources key.</p>
71
public String getBundle() {
73
ValueBinding vb = getValueBinding("bundle");
75
return (String) vb.getValue(getFacesContext());
84
* <p>Set the MessageResources key.</p>
86
* @param bundle The new key
88
public void setBundle(String bundle) {
96
* <p>Return the component family to which this component belongs.</p>
98
public String getFamily() {
100
return "org.apache.struts.faces.Errors";
106
* <p>Return the property name for which to report errors.</p>
108
public String getProperty() {
110
ValueBinding vb = getValueBinding("property");
112
return (String) vb.getValue(getFacesContext());
121
* <p>Set the property name for which to report errors.</p>
123
* @param property The new property name
125
public void setProperty(String property) {
127
this.property = property;
132
// ---------------------------------------------------- StateManager Methods
136
* <p>Restore the state of this component.</p>
138
* @param context <code>FacesContext</code> for the current request
139
* @param state State object from which to restore our state
141
public void restoreState(FacesContext context, Object state) {
143
Object values[] = (Object[]) state;
144
super.restoreState(context, values[0]);
145
bundle = (String) values[1];
146
property = (String) values[2];
152
* <p>Save the state of this component.</p>
154
* @param context <code>FacesContext</code> for the current request
156
public Object saveState(FacesContext context) {
158
Object values[] = new Object[3];
159
values[0] = super.saveState(context);
161
values[2] = property;