001: /*
002: * UserRoleForm.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 node. This form has the following fields,
014: * with default values in square brackets:
015: * <ul>
016: * <li><b>user</b> - The username. [REQUIRED]
017: * <li><b>role</b> - The user 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 UserRoleForm extends ActionForm {
025:
026: // --------------------------------------------------- Instance Variables
027:
028: /**
029: * The name of the user
030: */
031: private String user = null;
032:
033: /**
034: * The role of the user
035: */
036: private String role = null;
037:
038: // ----------------------------------------------------------- Properties
039:
040: /**
041: * Get the user
042: *@return String
043: */
044: public String getUser() {
045: return (user);
046: }
047:
048: /**
049: * Set the user
050: * @param user
051: */
052: public void setUser(String user) {
053: this .user = user;
054: }
055:
056: /**
057: * Get the role
058: *@return String
059: */
060: public String getRole() {
061: return (role);
062: }
063:
064: /**
065: * Set the role
066: * @param role
067: */
068: public void setRole(String role) {
069: this .role = role;
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 .user = null;
082: this .role = null;
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 (user == null || user.length() == 0)
099: errors.add("user", new ActionError("error.user.required"));
100: if (role == null || role.length() == 0)
101: errors.add("role", new ActionError("error.role.required"));
102:
103: return (errors);
104: }
105:
106: }
|