001: /*
002: * RoleForm.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 role. This form has the following fields,
014: * with default values in square brackets:
015: * <ul>
016: * <li><b>name</b> - The role name. [REQUIRED]
017: * <li><b>groupName</b> - The group of this role. [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 RoleForm extends ActionForm {
025:
026: // --------------------------------------------------- Instance Variables
027:
028: /**
029: * The name of the role
030: */
031: private String name = null;
032:
033: /**
034: * The name of the group
035: */
036: private String groupName = 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 group name
058: *@return String
059: */
060: public String getGroupName() {
061: return (groupName);
062: }
063:
064: /**
065: * Set the group name
066: * @param groupName
067: */
068: public void setGroupName(String groupName) {
069: this .groupName = groupName;
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:
081: public void reset(ActionMapping mapping, HttpServletRequest request) {
082: this .name = null;
083: this .groupName = null;
084:
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: ActionErrors errors = new ActionErrors();
100: if (name == null || name.length() == 0)
101: errors.add("name", new ActionError("error.name.required"));
102: if (groupName == null || groupName.length() == 0)
103: errors.add("groupName", new ActionError(
104: "error.groupname.required"));
105:
106: return (errors);
107: }
108:
109: }
|