
org.apache.struts.faces.component.ErrorsComponent Maven / Gradle / Ivy
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.struts.faces.component;
import javax.el.ValueExpression;
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
/**
* Custom component that replaces the Struts
* <html:errors>
tag.
*/
public class ErrorsComponent extends UIOutput {
// ------------------------------------------------------------ Constructors
/**
* Create a new {@link ErrorsComponent} with default properties.
*/
public ErrorsComponent() {
super();
setRendererType("org.apache.struts.faces.Errors");
}
// ------------------------------------------------------ Instance Variables
/**
* MessageResources attribute key to use for message lookup.
*/
private String bundle;
/**
* Property name of the property to report errors for.
*/
private String property;
// ---------------------------------------------------- Component Properties
/**
* Return the MessageResources key.
*/
public String getBundle() {
ValueExpression vb = getValueExpression("bundle");
if (vb != null) {
return (String) vb.getValue(getFacesContext().getELContext());
} else {
return bundle;
}
}
/**
* Set the MessageResources key.
*
* @param bundle The new key
*/
public void setBundle(String bundle) {
this.bundle = bundle;
}
/**
* Return the component family to which this component belongs.
*/
public String getFamily() {
return "org.apache.struts.faces.Errors";
}
/**
* Return the property name for which to report errors.
*/
public String getProperty() {
ValueExpression vb = getValueExpression("property");
if (vb != null) {
return (String) vb.getValue(getFacesContext().getELContext());
} else {
return property;
}
}
/**
* Set the property name for which to report errors.
*
* @param property The new property name
*/
public void setProperty(String property) {
this.property = property;
}
// ---------------------------------------------------- StateManager Methods
/**
* Restore the state of this component.
*
* @param context FacesContext
for the current request
* @param state State object from which to restore our state
*/
public void restoreState(FacesContext context, Object state) {
Object values[] = (Object[]) state;
super.restoreState(context, values[0]);
bundle = (String) values[1];
property = (String) values[2];
}
/**
* Save the state of this component.
*
* @param context FacesContext
for the current request
*/
public Object saveState(FacesContext context) {
Object values[] = new Object[3];
values[0] = super.saveState(context);
values[1] = bundle;
values[2] = property;
return values;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy