~ubuntu-branches/ubuntu/trusty/libstruts1.2-java/trusty-proposed

« back to all changes in this revision

Viewing changes to contrib/struts-faces/src/java/org/apache/struts/faces/component/ErrorsComponent.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2004-11-19 15:35:25 UTC
  • Revision ID: james.westby@ubuntu.com-20041119153525-mdu08a76z4zo67xt
Tags: upstream-1.2.4
ImportĀ upstreamĀ versionĀ 1.2.4

Show diffs side-by-side

added added

removed removed

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