UserEditAction.java
package com.mycim.webapp.actions.setting.security.user;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.beans.PropertyUtils;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.security.User;
import com.mycim.webapp.Constants;
import com.mycim.webapp.actions.CimSetupAction;
import com.mycim.webapp.forms.security.UserInfoForm;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author Johnson Wang
**/
public class UserEditAction extends CimSetupAction {
@Override
public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
// Populate the form bean instance
if (form == null) {
return (mapping.findForward("login"));
}
UserInfoForm theform = (UserInfoForm) form;
// Set a transactional control token to prevent double posting
saveToken(request);
// handle attributes tab page switch
String id = theform.getInstanceId().trim().toUpperCase();
// Construct a new value object that stores the id,
// named space(implicit, derived)
// object(hard coded)
User user = new User(id, getNamedSpace(ObjectList.USER_KEY, LocalContext.getFacilityRrn()),
ObjectList.USER_KEY);
// According to the instance's object, retrieve the value object
user = (User) getInstance(user);
// Copy value object properties to form bean.
PropertyUtils.copyProperties(theform, user);
theform.setPasswordConfirm(user.getPassword());
// if a value object does not exist, its instanceRrn will be set to 0
if (user.getInstanceRrn() == 0) {
theform.setTransId(Constants.CREATE_KEY);
theform.setFirstLoginPasswordExpired("on");
return (mapping.findForward("modify"));
}
if (StringUtils.isNotBlank(theform.getFirstLoginPasswordExpired()) &&
StringUtils.equals(theform.getFirstLoginPasswordExpired(), "1")) {
theform.setFirstLoginPasswordExpired("on");
}
theform.setTransId(Constants.MODIFY_KEY);
request.setAttribute("oldPassword", theform.getPassword());
return (mapping.findForward("modify"));
}
}