001: /*
002: * $Id: ErrorsComponent.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: package org.apache.struts.faces.component;
023:
024: import javax.faces.component.UIOutput;
025: import javax.faces.context.FacesContext;
026: import javax.faces.el.ValueBinding;
027:
028: /**
029: * <p>Custom component that replaces the Struts
030: * <code><html:errors></code> tag.</p>
031: */
032:
033: public class ErrorsComponent extends UIOutput {
034:
035: // ------------------------------------------------------------ Constructors
036:
037: /**
038: * <p>Create a new {@link ErrorsComponent} with default properties.</p>
039: */
040: public ErrorsComponent() {
041:
042: super ();
043: setRendererType("org.apache.struts.faces.Errors");
044:
045: }
046:
047: // ------------------------------------------------------ Instance Variables
048:
049: /**
050: * <p>MessageResources attribute key to use for message lookup.</p>
051: */
052: private String bundle = null;
053:
054: /**
055: * <p>Property name of the property to report errors for.</p>
056: */
057: private String property = null;
058:
059: // ---------------------------------------------------- Component Properties
060:
061: /**
062: * <p>Return the MessageResources key.</p>
063: */
064: public String getBundle() {
065:
066: ValueBinding vb = getValueBinding("bundle");
067: if (vb != null) {
068: return (String) vb.getValue(getFacesContext());
069: } else {
070: return bundle;
071: }
072:
073: }
074:
075: /**
076: * <p>Set the MessageResources key.</p>
077: *
078: * @param bundle The new key
079: */
080: public void setBundle(String bundle) {
081:
082: this .bundle = bundle;
083:
084: }
085:
086: /**
087: * <p>Return the component family to which this component belongs.</p>
088: */
089: public String getFamily() {
090:
091: return "org.apache.struts.faces.Errors";
092:
093: }
094:
095: /**
096: * <p>Return the property name for which to report errors.</p>
097: */
098: public String getProperty() {
099:
100: ValueBinding vb = getValueBinding("property");
101: if (vb != null) {
102: return (String) vb.getValue(getFacesContext());
103: } else {
104: return property;
105: }
106:
107: }
108:
109: /**
110: * <p>Set the property name for which to report errors.</p>
111: *
112: * @param property The new property name
113: */
114: public void setProperty(String property) {
115:
116: this .property = property;
117:
118: }
119:
120: // ---------------------------------------------------- StateManager Methods
121:
122: /**
123: * <p>Restore the state of this component.</p>
124: *
125: * @param context <code>FacesContext</code> for the current request
126: * @param state State object from which to restore our state
127: */
128: public void restoreState(FacesContext context, Object state) {
129:
130: Object values[] = (Object[]) state;
131: super .restoreState(context, values[0]);
132: bundle = (String) values[1];
133: property = (String) values[2];
134:
135: }
136:
137: /**
138: * <p>Save the state of this component.</p>
139: *
140: * @param context <code>FacesContext</code> for the current request
141: */
142: public Object saveState(FacesContext context) {
143:
144: Object values[] = new Object[3];
145: values[0] = super .saveState(context);
146: values[1] = bundle;
147: values[2] = property;
148: return values;
149:
150: }
151:
152: }
|