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