📄 staffmanageaction.java
字号:
package org.appfuse.webapp.action;
import java.util.List;
import org.apache.struts.actions.DispatchAction;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.appfuse.service.*;
import org.appfuse.model.*;
import org.appfuse.webapp.form.StaffForm;
import org.appfuse.util.ServiceFactory;
import org.appfuse.dao.hibernate.StaffDAOHibernate;
import java.util.ArrayList;
import org.appfuse.service.RoleManager;
import org.appfuse.model.Role;
import org.appfuse.model.*;
import org.appfuse.model.StaffRole;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionMessage;
import org.appfuse.util.exception.*;
import org.appfuse.util.exception.*;
import org.apache.struts.action.DynaActionForm;
public class StaffManageAction
extends BaseAction {
private static Log log = LogFactory.getLog(StaffManageAction.class);
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'delete' method...");
}
StaffManager mgr = (StaffManager) getBean("staffManager");
StaffForm userForm = (StaffForm) form;
mgr.removeStaff(userForm.getStaffno());
return list(mapping, form, request, response);
}
public ActionForward login(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
request.getSession().removeAttribute("staff");
if (log.isDebugEnabled()) {
log.debug("entering 'login' method...");
}
StaffManager mgr = (StaffManager) getBean("staffManager");
RoleManager roleMgr = (RoleManager) getBean("roleManager");
AuthManager authMgr = (AuthManager) getBean("authManager");
ModuleManager moduleMgr = (ModuleManager) getBean("moduleManager");
FunctionManager actionMgr = (FunctionManager) getBean("functionManager");
StaffForm staffForm = (StaffForm) form;
Staff staff = mgr.getStaff(staffForm.getStaffname(),
staffForm.getStaffpwd());
log.debug("staff:" + staff.getStaffno() + "|" + staff.getStaffname() +
"|" + staff.getStaffpwd());
List staffAuths = new ArrayList();
if (staff != null) {
List list = mgr.getRoles(staff.getStaffno());
try {
for (int i = 0; i < list.size(); i++) {
Role role = (Role) list.get(i);
List auths = roleMgr.getRoleAuth(role);
for (int j = 0; j < auths.size(); j++) {
RoleAuth roleAuth = (RoleAuth) auths.get(j);
Auth auth = authMgr.getAuth(roleAuth.getAuthid());
Module module = moduleMgr.getModule(auth.
getModuleid());
Function function = actionMgr.getFunction(auth.
getFunctionid());
staffAuths.add(new Property(module.getModuleURL(),
function.getFunctionname()));
log.debug("[" + module.getModuleURL() + "][" +
function.getFunctionname() + "]");
}
}
}
catch (Exception ex) {
log.error(ex);
}
staff.setAuthList(staffAuths);
request.getSession().setAttribute("staff", staff);
return mapping.findForward("index");
}
else {
ActionMessages errors = new ActionMessages();
errors.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("errors.login"));
saveErrors(request, errors);
return mapping.findForward("error");
}
}
public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'list' method...");
}
StaffManager mgr = (StaffManager) getBean("staffManager");
List lst = null;
try {
lst = mgr.getStaffs(new Staff());
}
catch (Exception es) {
log.error("in list: ", es);
}
request.setAttribute("staffs", lst);
return mapping.findForward("list");
}
public ActionForward register(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'save' method...");
}
if (isCancelled(request)) {
return list(mapping, form, request, response);
}
StaffManager mgr = (StaffManager) getBean("staffManager");
StaffForm userForm = (StaffForm) form;
Staff staff = new Staff();
copyProperties(staff, userForm);
mgr.saveStaff(staff);
return mapping.findForward("success");
}
public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'save' method...");
}
if (isCancelled(request)) {
return list(mapping, form, request, response);
}
StaffManager mgr = (StaffManager) getBean("staffManager");
StaffForm userForm = (StaffForm) form;
Staff staff = new Staff();
copyProperties(staff, userForm);
mgr.saveStaff(staff);
return list(mapping, form, request, response);
}
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'update' method...");
}
StaffManager mgr = (StaffManager) getBean("staffManager");
if (isCancelled(request)) {
return list(mapping, form, request, response);
}
StaffForm userForm = (StaffForm) form;
request.setAttribute("staff", mgr.getStaff(userForm.getStaffno()));
return mapping.findForward("update");
}
public ActionForward search(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'search' method...");
}
StaffManager mgr = (StaffManager) getBean("staffManager");
String no = request.getParameter("staffno");
if (no == null || no.length() < 1) {
return list(mapping, form, request, response);
}
ArrayList list = new ArrayList(1);
try {
list.add(mgr.getStaff(Integer.parseInt(no)));
}
catch (Exception es) {
log.error(es);
}
request.setAttribute("staffs", list);
return mapping.findForward("list");
}
public ActionForward unspecified(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
return list(mapping, form, request, response);
}
public ActionForward test(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
StaffManager mgr = (StaffManager) getBean("staffManager");
DynaActionForm dynaForm = (DynaActionForm) form;
Staff staff = new Staff();
staff.setStaffname((String)dynaForm.get("staffname"));
staff.setStaffpwd((String)dynaForm.get("staffpwd"));
mgr.saveStaff(staff);
return list(mapping, form, request, response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -