[Commits] (bcm) replace DynaActionForm with an explicit UserForm.
commits at osafoundation.org
commits at osafoundation.org
Thu Apr 14 10:56:54 PDT 2005
Commit by: bcm
Modified files:
server/docs/TODO.txt 1.54 1.55
server/web/src/org/osaf/cosmo/ui/UserForm.java None 1.1
server/web/src/org/osaf/cosmo/ui/UserAction.java 1.5 1.6
server/web/web/WEB-INF/struts-config.xml 1.6 1.7
Log message:
replace DynaActionForm with an explicit UserForm.
ViewCVS links:
http://cvs.osafoundation.org/index.cgi/server/docs/TODO.txt.diff?r1=text&tr1=1.54&r2=text&tr2=1.55
http://cvs.osafoundation.org/index.cgi/server/web/src/org/osaf/cosmo/ui/UserForm.java?rev=1.1&content-type=text/vnd.viewcvs-markup
http://cvs.osafoundation.org/index.cgi/server/web/src/org/osaf/cosmo/ui/UserAction.java.diff?r1=text&tr1=1.5&r2=text&tr2=1.6
http://cvs.osafoundation.org/index.cgi/server/web/web/WEB-INF/struts-config.xml.diff?r1=text&tr1=1.6&r2=text&tr2=1.7
Index: server/docs/TODO.txt
diff -u server/docs/TODO.txt:1.54 server/docs/TODO.txt:1.55
--- server/docs/TODO.txt:1.54 Wed Apr 13 16:50:28 2005
+++ server/docs/TODO.txt Thu Apr 14 10:56:52 2005
@@ -6,7 +6,6 @@
web:
- * replace DynaActionForm with a UserForm
* get tests running again
docs:
Index: server/web/web/WEB-INF/struts-config.xml
diff -u server/web/web/WEB-INF/struts-config.xml:1.6 server/web/web/WEB-INF/struts-config.xml:1.7
--- server/web/web/WEB-INF/struts-config.xml:1.6 Wed Apr 13 16:50:28 2005
+++ server/web/web/WEB-INF/struts-config.xml Thu Apr 14 10:56:53 2005
@@ -7,22 +7,8 @@
<struts-config>
<form-beans>
- <form-bean name="createUserForm"
- type="org.apache.struts.validator.DynaValidatorForm">
- <form-property name="username" type="java.lang.String"/>
- <form-property name="email" type="java.lang.String"/>
- <form-property name="password" type="java.lang.String"/>
- <form-property name="confirm" type="java.lang.String"/>
- <form-property name="role" type="java.lang.String[]"/>
- </form-bean>
- <form-bean name="updateUserForm"
- type="org.apache.struts.validator.DynaValidatorForm">
- <form-property name="id" type="java.lang.String"/>
- <form-property name="email" type="java.lang.String"/>
- <form-property name="password" type="java.lang.String"/>
- <form-property name="confirm" type="java.lang.String"/>
- <form-property name="role" type="java.lang.String[]"/>
- </form-bean>
+ <form-bean name="createUserForm" type="org.osaf.cosmo.ui.UserForm"/>
+ <form-bean name="updateUserForm" type="org.osaf.cosmo.ui.UserForm"/>
</form-beans>
<global-exceptions>
Index: server/web/src/org/osaf/cosmo/ui/UserAction.java
diff -u server/web/src/org/osaf/cosmo/ui/UserAction.java:1.5 server/web/src/org/osaf/cosmo/ui/UserAction.java:1.6
--- server/web/src/org/osaf/cosmo/ui/UserAction.java:1.5 Wed Apr 13 16:50:28 2005
+++ server/web/src/org/osaf/cosmo/ui/UserAction.java Thu Apr 14 10:56:53 2005
@@ -21,7 +21,6 @@
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
-import org.apache.struts.action.DynaActionForm;
import org.springframework.dao.DataIntegrityViolationException;
@@ -60,40 +59,6 @@
* List of the Roles to which a user can be assigned.
*/
public static final String ATTR_ROLES = "Roles";
- /**
- * The form attribute in which this action expects to find the
- * id: <code>id</code>
- */
- public static final String FORMATTR_ID = "id";
- /**
- * The form attribute in which this action expects to find the
- * username: <code>username</code>
- */
- public static final String FORMATTR_USERNAME = "username";
- /**
- * The form attribute in which this action expects to find the
- * username: <code>email</code>
- */
- public static final String FORMATTR_EMAIL = "email";
- /**
- * The form attribute in which this action expects to find the
- * user's password when handling a form submission:
- * <code>password</code>
- */
- public static final String FORMATTR_PASSWORD = "password";
- /**
- * The form attribute in which this action expects to find the
- * confirming password when handling a form submission:
- * <code>confirm</code>
- */
- public static final String FORMATTR_CONFIRM = "confirm";
- /**
- * The form attribute in which this action expects to find the
- * ids of the roles to which the user will be assigned when
- * handling a form submission (represented as a
- * <code>String[]</code>: * <code>role</code>
- */
- public static final String FORMATTR_ROLE = "role";
private ProvisioningManager mgr;
@@ -111,16 +76,15 @@
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
- DynaActionForm userForm = (DynaActionForm) form;
+ UserForm userForm = (UserForm) form;
// the User may have previously been set by a request
// attribute. if not, look to see if the form has id info. if
// not, we're viewing the user for the first time.
User user = (User) request.getAttribute(ATTR_USER);
if (user == null) {
- String id = (String) userForm.get(FORMATTR_ID);
- if (id != null && ! id.equals("")) {
- user = mgr.getUser(id);
+ if (userForm.getId() != null && ! userForm.getId().equals("")) {
+ user = mgr.getUser(userForm.getId());
}
else {
String username = request.getParameter(PARAM_USERNAME);
@@ -148,7 +112,7 @@
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
- DynaActionForm userForm = (DynaActionForm) form;
+ UserForm userForm = (UserForm) form;
User formUser = new User();
populateUser(formUser, userForm);
@@ -161,7 +125,7 @@
request.setAttribute(ATTR_USER, user);
saveConfirmationMessage(request, MSG_CONFIRM_CREATE);
} catch (DataIntegrityViolationException e) {
- saveErrorMessage(request, MSG_ERROR_EXISTS, FORMATTR_USERNAME);
+ saveErrorMessage(request, MSG_ERROR_EXISTS, userForm.getUsername());
return mapping.findForward(OSAFStrutsConstants.FWD_FAILURE);
}
@@ -176,15 +140,15 @@
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
- DynaActionForm userForm = (DynaActionForm) form;
+ UserForm userForm = (UserForm) form;
if (isCancelled(request)) {
- resetUpdateForm(userForm);
+ userForm.reset(mapping, request);
return mapping.findForward(OSAFStrutsConstants.FWD_CANCEL);
}
try {
- User formUser = mgr.getUser((String) userForm.get(FORMATTR_ID));
+ User formUser = mgr.getUser(userForm.getId());
populateUser(formUser, userForm);
if (log.isDebugEnabled()) {
log.debug("updating user " + formUser.getUsername());
@@ -194,7 +158,7 @@
request.setAttribute(ATTR_USER, user);
saveConfirmationMessage(request, MSG_CONFIRM_UPDATE);
} catch (DataIntegrityViolationException e) {
- saveErrorMessage(request, MSG_ERROR_EXISTS, FORMATTR_USERNAME);
+ saveErrorMessage(request, MSG_ERROR_EXISTS, userForm.getUsername());
return mapping.findForward(OSAFStrutsConstants.FWD_FAILURE);
}
@@ -231,7 +195,7 @@
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
- DynaActionForm userForm = (DynaActionForm) form;
+ UserForm userForm = (UserForm) form;
// if the form has not yet been submitted, default the role
// selection
@@ -239,7 +203,7 @@
null) {
Role userRole = mgr.getRoleByName(CosmoSecurityManager.ROLE_USER);
String[] roleIds = { userRole.getId().toString() };
- userForm.set(FORMATTR_ROLE, roleIds);
+ userForm.setRole(roleIds);
}
request.setAttribute(ATTR_USERS, getSortedUsers());
@@ -276,13 +240,14 @@
return roles;
}
- private void populateUser(User user, DynaActionForm form) {
+ private void populateUser(User user, UserForm form) {
if (user.getId() == null) {
- user.setUsername((String) form.get(FORMATTR_USERNAME));
+ // this is a creation action, where username is modifiable
+ user.setUsername(form.getUsername());
}
- user.setEmail((String) form.get(FORMATTR_EMAIL));
- user.setPassword((String) form.get(FORMATTR_PASSWORD));
- String[] roleIds = (String[]) form.get(FORMATTR_ROLE);
+ user.setEmail(form.getEmail());
+ user.setPassword(form.getPassword());
+ String[] roleIds = form.getRole();
HashMap idx = new HashMap();
for (int i=0; i<roleIds.length; i++) {
Role role = mgr.getRole(roleIds[i]);
@@ -297,18 +262,12 @@
}
}
- private void populateUpdateForm(DynaActionForm form, User user) {
- form.set(FORMATTR_ID, user.getId().toString());
- form.set(FORMATTR_EMAIL, user.getEmail());
+ private void populateUpdateForm(UserForm form, User user) {
+ form.setId(user.getId());
+ form.setEmail(user.getEmail());
// never set password in the form
Role[] roles = (Role[]) user.getRoles().toArray(new Role[0]);
- form.set(FORMATTR_ROLE, mapRolesToRoleIds(roles));
- }
-
- private void resetUpdateForm(DynaActionForm form) {
- form.set(FORMATTR_EMAIL, null);
- form.set(FORMATTR_PASSWORD, null);
- form.set(FORMATTR_ROLE, new String[0]);
+ form.setRole(mapRolesToRoleIds(roles));
}
private String[] mapRolesToRoleIds(Role[] roles) {
More information about the Commits
mailing list