001: package hero.struts.forms;
002:
003: import javax.servlet.http.HttpServletRequest;
004: import org.apache.struts.action.ActionError;
005: import org.apache.struts.action.ActionErrors;
006: import org.apache.struts.action.ActionForm;
007: import org.apache.struts.action.ActionMapping;
008:
009: /**
010: * Form bean for property. This form has the following fields,
011: * with default values in square brackets:
012: * <ul>
013: * <li><b>key</b> - The property key. [REQUIRED]
014: * <li><b>value</b> - The property value. [REQUIRED]
015: * </ul>
016: *
017: * @author Miguel Valdes Faura
018: * @version $Revision: 1.1 $ $Date: 2004/07/30 14:57:57 $
019: */
020:
021: public final class PropertyForm extends ActionForm {
022:
023: // --------------------------------------------------- Instance Variables
024:
025: /**
026: * The property key.
027: */
028: private String key = null;
029:
030: /**
031: * The property value
032: */
033: private String value = null;
034:
035: // ----------------------------------------------------------- Properties
036:
037: /**
038: * Return the property key.
039: */
040: public String getKey() {
041:
042: return (this .key);
043: }
044:
045: /**
046: * Set the property key.
047: *
048: * @param key The new property key
049: */
050: public void setKey(String key) {
051:
052: this .key = key;
053: }
054:
055: /**
056: * Return the property value.
057: */
058: public String getValue() {
059:
060: return (this .value);
061: }
062:
063: /**
064: * Set the property value.
065: *
066: * @param value The new property value
067: */
068: public void setValue(String value) {
069:
070: this .value = value;
071: }
072:
073: // --------------------------------------------------------- Public Methods
074:
075: /**
076: * Reset all properties to their default values.
077: *
078: * @param mapping The mapping used to select this instance
079: * @param request The servlet request we are processing
080: */
081: public void reset(ActionMapping mapping, HttpServletRequest request) {
082:
083: this .key = null;
084: this .value = null;
085: }
086:
087: /**
088: * Validate the properties that have been set from this HTTP request,
089: * and return an <code>ActionErrors</code> object that encapsulates any
090: * validation errors that have been found. If no errors are found, return
091: * <code>null</code> or an <code>ActionErrors</code> object with no
092: * recorded error messages.
093: *
094: * @param mapping The mapping used to select this instance
095: * @param request The servlet request we are processing
096: */
097: public ActionErrors validate(ActionMapping mapping,
098: HttpServletRequest request) {
099:
100: ActionErrors errors = new ActionErrors();
101:
102: if (key == null || key.length() == 0)
103: errors.add("key", new ActionError("error.key.required"));
104: if (value == null || value.length() == 0)
105: errors
106: .add("value", new ActionError(
107: "error.value.required"));
108:
109: return (errors);
110:
111: }
112: }
|