SelectReaderAction

阅读更多
/*

* All rights reserved.
*
* $Id: SelectReaderAction.java,v 1.14 2004/06/10 15:06:48 guoq Exp $
*/

package cn.com.detech.deinfo.mission.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.StringTokenizer;

import cn.com.detech.deinfo.mission.model.ReaderBean;
import cn.com.detech.deinfo.platform.DeInfoConstant;
import cn.com.detech.deinfo.users.BeanDepartment;
import cn.com.detech.deinfo.users.BeanGroup;
import cn.com.detech.deinfo.users.BeanPosition;
import cn.com.detech.deinfo.users.BeanUser;
import cn.com.detech.deinfo.users.CacheDepartments;
import cn.com.detech.deinfo.users.CacheGroups;
import cn.com.detech.deinfo.users.CacheObjects;
import cn.com.detech.deinfo.users.CachePositions;
import cn.com.detech.deinfo.users.CacheUsers;
import cn.com.detech.deinfo.users.User;
import cn.com.detech.struts.action.DEBaseAction;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;



/**
* 传阅人名单选择ActionBean类
* NOTE: This source is automatically generated please do not modify this file.  Either subclass or
*       remove the record in src/records/definitions.
* @author 曾刚
*/
public class SelectReaderAction extends DEBaseAction
{
public SelectReaderAction(){
FUNCTION_POINT = "";
}

protected static Class getClassName(){
return SelectReaderAction.class;
}

    //------------------------------------------------------ Local Forwards
    static final String FORWARD_success = "success";
    static final String FORWARD_failure = "failure";
static final String FORWARD_Select = "Select";
static final String FORWARD_Select2 = "Select2";//add by weij;
static final String FORWARD_Back = "Back";//add by weij;
    static final String FORWARD_ChangeDept = "ChangeDept";
    static final String FORWARD_ChangeGroup = "ChangeGroup";
    static final String FORWARD_Save = "Save";
    /*static final*/ String DEFAULT_POSITION = "待定";

    //------------------------------------------------------ Action Methods

/**
* Process the specified HTTP request, and create the corresponding HTTP
* response (or forward to another web component that will create it).
* Return an ActionForward instance describing where and how
* control should be forwarded, or null if the response has
* already been completed.
*
* @param mapping The ActionMapping used to select this instance
* @param aform The optional ActionForm bean for this request (if any)
* @param request 待处理的HTTP请求
* @param response 生成的HTTP回应
* @return 页面迁移
* @throws Exception
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm myform,
HttpServletRequest request,
HttpServletResponse response,
User user)
throws Exception
{try{
        SelectReaderForm form = (SelectReaderForm)myform;
        String action = form.getAction();
        if ( action == null ) {
            action = "Select";
        }
        log.debug("enter sel people ,action is:"+action);
       
DEFAULT_POSITION=getMessage("mission.selectreader.tobe");
       
if(action.equalsIgnoreCase("Select")){
return doSelect(mapping, form, request, response, user);
}
//      add by weij;
if(action.equalsIgnoreCase("Select2")){
return doSelect2(mapping, form, request, response, user);
}
       
        if(action.equalsIgnoreCase("ChangeDept")){
            return doChangeDept(mapping, form, request, response, user);
        }
       
        if(action.equalsIgnoreCase("ChangeGroup")){
            return doChangeGroup(mapping, form, request, response, user);
        }

        if(action.equalsIgnoreCase("Save")){
            return doSave(mapping, form, request, response, user);
        }
       
        if(action.equalsIgnoreCase("Cancel")){
            return doCancel(mapping, form, request, response, user);
        }
//      add by weij;
if(action.equalsIgnoreCase("Save2")){
return doSave2(mapping, form, request, response, user);
}
        }catch(Exception e){e.printStackTrace();
        }


        return mapping.findForward(FORWARD_Select);
}

/**
*
* @param mapping
* @param form
* @param request
* @throws Exception
* @return ActionForward
*/
public ActionForward doSelect(ActionMapping mapping,
SelectReaderForm form,
HttpServletRequest request,
HttpServletResponse response,
User user)
throws Exception {

// Add your logic code here
form.reset();
HttpSession session = request.getSession();
CacheObjects objCacheObjects = (CacheObjects)session.getServletContext().getAttribute(DeInfoConstant.PLATFORM_CONTEXT);
CacheUsers users = objCacheObjects.getUsers();
CacheDepartments departments = objCacheObjects.getDepartments();
        CacheGroups groups = objCacheObjects.getGroups();

form.reset();
ArrayList deptList = departments.getDepartments();
BeanDepartment nbd = new BeanDepartment();
nbd.setDeptID(9998);
nbd.setDepartmentName(getMessage("mission.selectreader.sel_dept"));
deptList.add(0, nbd);
form.setDeptList(deptList);               
form.setSelDeptID("9998");
       
        //加用户组
        Iterator it = groups.getIterator0();
        ArrayList groupList = new ArrayList();
        while (it.hasNext()) {
            BeanGroup nbg = (BeanGroup) it.next();
            groupList.add(nbg);
        }
        BeanGroup nbg = new BeanGroup();
        nbg.setGroupID(9998);
        nbg.setGroupName(getMessage("mission.selectreader.sel_group"));
        groupList.add(0, nbg);
        form.setGroupList(groupList);
        form.setSelGroupID("9998");
      
form.setEmpList(new ArrayList());
               
ArrayList readerList = new ArrayList();
session.removeAttribute("ReaderIDs");//add by weij;      
/*ArrayList readerIDList = (ArrayList)session.getAttribute("ReaderIDs");
if (readerIDList == null)
readerIDList = new ArrayList();
session.setAttribute("readerIDList", readerIDList);     //生成副本
if (readerIDList != null && readerIDList.size() > 0) {
Iterator ior = readerIDList.iterator();
           
ArrayList readerNameList = new ArrayList();
session.removeAttribute("ReaderNames");//add by weij;
String tmpStr = (String)session.getAttribute("ReaderNames");
if (tmpStr == null)
tmpStr = new String("");
session.setAttribute("readerNameStr", tmpStr);      //生成副本
if (tmpStr != null && !tmpStr.equals("")) {
StringTokenizer st = new StringTokenizer(tmpStr, "#");
while(st.hasMoreTokens()) {
readerNameList.add((String)st.nextElement());
}
}
Iterator ier = readerNameList.iterator();
                       
while (ior.hasNext()) {
ReaderBean nrb = new ReaderBean();
int userID = Integer.parseInt((String)ior.next());
String readerStr = (String)ier.next();
               
StringTokenizer st = new StringTokenizer(readerStr, "&&&&&&&&");
if(st.hasMoreTokens()) {
nrb.setUserName((String)st.nextElement());
nrb.setDeptName((String)st.nextElement());
}
StringTokenizer st1 = new StringTokenizer((String)st.nextElement(), "&&");
if(st1.hasMoreTokens()) {
nrb.setPositionName((String)st1.nextElement());
}
               
nrb.setUserID(userID);
readerList.add(nrb);
}
form.setReaderList(readerList);
String[] as = new String[1];
as[0] = "";
form.setSelectedIDStr(as);
}
else*/
form.setReaderList(readerList);
                               
return (mapping.findForward(FORWARD_Select));
}
   
/**
*
* @param mapping
* @param form
* @param request
* @throws Exception
* @return ActionForward
*/
public ActionForward doSelect2(ActionMapping mapping,
SelectReaderForm form,
HttpServletRequest request,
HttpServletResponse response,
User user)
throws Exception {

// Add your logic code here
form.reset();
HttpSession session = request.getSession();
CacheObjects objCacheObjects = (CacheObjects)session.getServletContext().getAttribute(DeInfoConstant.PLATFORM_CONTEXT);
CacheUsers users = objCacheObjects.getUsers();
CacheDepartments departments = objCacheObjects.getDepartments();
        CacheGroups groups = objCacheObjects.getGroups();

form.reset();
ArrayList deptList = departments.getDepartments();
BeanDepartment nbd = new BeanDepartment();
nbd.setDeptID(9998);
nbd.setDepartmentName(getMessage("mission.selectreader.sel_dept"));
deptList.add(0, nbd);
form.setDeptList(deptList);               
form.setSelDeptID("9998");
               
        //加用户组
        Iterator it = groups.getIterator0();
        ArrayList groupList = new ArrayList();
        while (it.hasNext()) {
            BeanGroup nbg = (BeanGroup) it.next();
            groupList.add(nbg);
        }
        BeanGroup nbg = new BeanGroup();
        nbg.setGroupID(9998);
        nbg.setGroupName(getMessage("mission.selectreader.sel_group"));
        groupList.add(0, nbg);
        form.setGroupList(groupList);
        form.setSelGroupID("9998");
       
form.setEmpList(new ArrayList());
               
ArrayList readerList = new ArrayList();
session.removeAttribute("ReaderIDs2");//add by weij;      
/*ArrayList readerIDList = (ArrayList)session.getAttribute("ReaderIDs2");
if (readerIDList == null)
readerIDList = new ArrayList();
session.setAttribute("readerIDList", readerIDList);     //生成副本
if (readerIDList != null && readerIDList.size() > 0) {
Iterator ior = readerIDList.iterator();
           
ArrayList readerNameList = new ArrayList();
session.removeAttribute("ReaderNames");//add by weij;
String tmpStr = (String)session.getAttribute("ReaderNames");
if (tmpStr == null)
tmpStr = new String("");
session.setAttribute("readerNameStr", tmpStr);      //生成副本
if (tmpStr != null && !tmpStr.equals("")) {
StringTokenizer st = new StringTokenizer(tmpStr, "#");
while(st.hasMoreTokens()) {
readerNameList.add((String)st.nextElement());
}
}
Iterator ier = readerNameList.iterator();
                       
while (ior.hasNext()) {
ReaderBean nrb = new ReaderBean();
int userID = Integer.parseInt((String)ior.next());
String readerStr = (String)ier.next();
               
StringTokenizer st = new StringTokenizer(readerStr, "&&&&&&&&");
if(st.hasMoreTokens()) {
nrb.setUserName((String)st.nextElement());
nrb.setDeptName((String)st.nextElement());
}
StringTokenizer st1 = new StringTokenizer((String)st.nextElement(), "&&");
if(st1.hasMoreTokens()) {
nrb.setPositionName((String)st1.nextElement());
}
               
nrb.setUserID(userID);
readerList.add(nrb);
}
form.setReaderList(readerList);
String[] as = new String[1];
as[0] = "";
form.setSelectedIDStr(as);
}
else*/
form.setReaderList(readerList);
                               
return (mapping.findForward(FORWARD_Select2));
}
   
    /**
     *
     * @param mapping
     * @param form
     * @param request
     * @throws Exception
     * @return ActionForward
     */
    public ActionForward doChangeDept(ActionMapping mapping,
                              SelectReaderForm form,
                              HttpServletRequest request,
                              HttpServletResponse response,
                              User user)
        throws Exception {

      // Add your logic code here
        HttpSession session = request.getSession();
        CacheObjects objCacheObjects = (CacheObjects)session.getServletContext().getAttribute(DeInfoConstant.PLATFORM_CONTEXT);
        CacheUsers users = objCacheObjects.getUsers();
        CachePositions positions = objCacheObjects.getPositions();
        CacheDepartments departments = objCacheObjects.getDepartments();

        String selDeptID = form.getSelDeptID();
        String readerNameStr = form.getReaderNameStr();
        session.setAttribute("readerNameStr", readerNameStr);
        String[] tmpIDArray = form.getSelectedIDStr();
        if(tmpIDArray!=null)
        log.debug("tmpIDArray.length == "+tmpIDArray.length);

        form.reset2();

        ArrayList readerIDList = new ArrayList();
        if (tmpIDArray != null) {
            for (int i = 0; i < tmpIDArray.length; i ++) {
                readerIDList.add(tmpIDArray[i]);
            }
            session.setAttribute("readerIDList", readerIDList);
        }
       
        ArrayList tmpList = new ArrayList();
        ArrayList empList = new ArrayList();

        if (selDeptID == null || selDeptID.equals("") || selDeptID.equals("0")) {
            form.setAction("Select");
            return (mapping.findForward(FORWARD_Select));
        }
       
        if (selDeptID.equals("9998")) {
            form.setEmpList(empList);
        }
        else {
            int deptID = Integer.parseInt(selDeptID);
            String departmentName = ((BeanDepartment)departments.getDeptByID(deptID)).getDepartmentName();
            tmpList = users.getUsersByDeptID(deptID);
           
            Iterator it = tmpList.iterator();
            while(it.hasNext()) {
                BeanUser nbu = (BeanUser)it.next();
               
                int userID = nbu.getUserID();
                int positionID = 0;
                if (userID == 1) { //如果是系统管理员
                    positionID = 1; //直接设置其职务为待定
                } else {
                    positionID = users.getUserPosition(userID, deptID);
                }
                //int positionID = users.getUserPosition(userID, deptID);
                BeanPosition beanp = (BeanPosition) positions.getPositionByID(positionID);
                String positionName = getMessage("mission.selectreader.tobe");
                if(beanp!=null) positionName = beanp.getPosition();
                String userName = "";
                BeanUser buser = (BeanUser) users.getUserByID(userID);
                if (buser != null) {
                    userName = buser.getUserName();
                }
                //String userName = ((BeanUser)users.getUserByID(userID)).getUserName();
               
                ReaderBean rb = new ReaderBean();
                rb.setUserID(userID);
                rb.setUserName(userName);
                rb.setDeptID(deptID);
                rb.setDeptName(departmentName);
                rb.setPositionID(positionID);
                rb.setPositionName(positionName);
               
                empList.add(rb);
            }
        }

        form.setEmpList(empList);
        form.setSelDeptID(selDeptID);
        form.setSelGroupID("9998");
       
        ArrayList readerList = new ArrayList();
        readerIDList = (ArrayList) session.getAttribute("readerIDList");
        if (readerIDList != null && readerIDList.size() > 0) {
            Iterator ior = readerIDList.iterator();

            while (ior.hasNext()) {
                ReaderBean nrb = new ReaderBean();
                String ids = (String) ior.next();
                StringTokenizer st = new StringTokenizer(ids, "#");
                int i = 0;
                int userID = 0;
                int deptID = 0;
                int positionID = 0;
                while (st.hasMoreTokens()) {
                    if (i == 0)
                        userID = Integer.parseInt((String) st.nextElement());
                    else if (i == 1)
                        deptID = Integer.parseInt((String) st.nextElement());
                    else if (i == 2)
                        positionID =
                            Integer.parseInt((String) st.nextElement());
                    ;
                    i++;
                }

                String userName =
                    ((BeanUser) users.getUserByID(userID)).getUserName();
                String deptName =
                    ((BeanDepartment) departments.getDeptByID(deptID))
                        .getDepartmentName();
                String positionName = getPosition(positions, positionID);

                nrb.setUserID(userID);
                nrb.setUserName(userName);
                nrb.setDeptID(deptID);
                nrb.setDeptName(deptName);
                nrb.setPositionID(positionID);
                nrb.setPositionName(positionName);
                readerList.add(nrb);
            }
        /*ArrayList readerList = new ArrayList();
        readerIDList = (ArrayList)session.getAttribute("readerIDList");
        if (readerIDList != null && readerIDList.size() > 0) {
            Iterator ior = readerIDList.iterator();
           

            ArrayList readerNameList = new ArrayList();
            String tmpStr = (String)session.getAttribute("readerNameStr");
            if (tmpStr != null && !tmpStr.equals("")) {
                StringTokenizer st = new StringTokenizer(tmpStr, "#");
                while(st.hasMoreTokens()) {
                    readerNameList.add((String)st.nextElement());
                }
            }
            Iterator ier = readerNameList.iterator();
                       
            while (ior.hasNext()) {
                ReaderBean nrb = new ReaderBean();
                int userID = Integer.parseInt((String)ior.next());
                String readerStr = "";
                if(ier.hasNext())
                readerStr = (String)ier.next();
               
                StringTokenizer st = new StringTokenizer(readerStr, "&&&&&&&&");
                if(st.hasMoreTokens()) {
                    nrb.setUserName((String)st.nextElement());
                    nrb.setDeptName((String)st.nextElement());
                }
                String ststr = "";
                if(st.hasMoreElements()) ststr = (String)st.nextElement();
               
                StringTokenizer st1 = new StringTokenizer(ststr, "&&");
                if(st1.hasMoreTokens()) {
                    nrb.setPositionName((String)st1.nextElement());
                }
               
               
                nrb.setUserID(userID);
                readerList.add(nrb);
            }*/
            form.setReaderList(readerList);
            form.setSelectedIDStr(null);
        }
        else
            form.setReaderList(readerList);
           

        return (mapping.findForward(FORWARD_Select));
    }   
   
    /**
     *
     * @param mapping
     * @param form
     * @param request
     * @throws Exception
     * @return ActionForward
     */
    public ActionForward doChangeGroup(ActionMapping mapping,
                              SelectReaderForm form,
                              HttpServletRequest request,
                              HttpServletResponse response,
                              User user)
        throws Exception {

            // Add your logic code here
            HttpSession session = request.getSession();
            CacheObjects objCacheObjects =
                (CacheObjects) session.getServletContext().getAttribute(
                    DeInfoConstant.PLATFORM_CONTEXT);
            CacheUsers users = objCacheObjects.getUsers();
            CacheDepartments departments = objCacheObjects.getDepartments();
            CachePositions positions = objCacheObjects.getPositions();
            CacheGroups groups = objCacheObjects.getGroups();

            String selGroupID = form.getSelGroupID();
            String readerNameStr = form.getReaderNameStr();
            //session.removeAttribute("readerNameStr");
            session.setAttribute("readerNameStr", readerNameStr);
            String[] tmpIDArray = form.getSelectedIDStr();

            form.reset();

            ArrayList readerIDList = new ArrayList();
            if (tmpIDArray != null) {
                for (int i = 0; i < tmpIDArray.length; i++) {
                    readerIDList.add(tmpIDArray[i]);
                }
            }
            //session.removeAttribute("readerIDList");
            session.setAttribute("readerIDList", readerIDList);

            ArrayList empList = new ArrayList();
            ArrayList tmpList = new ArrayList();
            HashMap hm = new HashMap();

            if (selGroupID == null
                || selGroupID.equals("")
                || selGroupID.equals("0")) {
                form.setAction("Select");
                return (mapping.findForward(FORWARD_Select));
            }

            if (selGroupID.equals("9998")) {
                form.setEmpList(empList);
            } else {
                tmpList = users.getUsersByGroupID(Integer.parseInt(selGroupID));

                Iterator it = tmpList.iterator();
                while (it.hasNext()) {
                    BeanGroup bg = (BeanGroup) it.next();
                    int userID = bg.getUserID();
                    int deptID = bg.getDeptID();
                    //要排除用户组中用户重复的情况
                    if (userID == 0 && deptID == 0) { //所有用户都属于该用户组
                        ArrayList alist = users.getUsers();
                        Iterator ior = alist.iterator();
                        while (ior.hasNext()) {
                            BeanUser bu = (BeanUser) ior.next();
                            int uid = bu.getUserID();
                            String userName = users.getUserByID(uid).getUserName();
                            int did =
                                ((BeanDepartment) (users
                                    .getDeptsByUserID(uid)
                                    .get(0)))
                                    .getDeptID();
                            String departmentName =
                                ((BeanDepartment) (users
                                    .getDeptsByUserID(uid)
                                    .get(0)))
                                    .getDepartmentName();
                            int pid = users.getUserPosition(uid, did);
                            String positionName = getPosition(positions, pid);

                            ReaderBean rb = new ReaderBean();
                            rb.setUserID(uid);
                            rb.setUserName(userName);
                            rb.setDeptID(did);
                            rb.setDeptName(departmentName);
                            rb.setPositionID(pid);
                            rb.setPositionName(positionName);

                            hm.put(new Integer(uid), rb);
                        }
                    } else if (userID == 0 && deptID != 0) { //某部门下的所有用户属于该用户组
                        ArrayList alist = users.getUsersByDeptID(deptID);
                        Iterator irr = alist.iterator();
                        while (irr.hasNext()) {
                            BeanUser bu = (BeanUser) irr.next();
                            int uid = bu.getUserID();
                            String userName = users.getUserByID(uid).getUserName();
                            String departmentName =
                                ((BeanDepartment) departments.getDeptByID(deptID))
                                    .getDepartmentName();
                            int pid = users.getUserPosition(uid, deptID);
                            String positionName = getPosition(positions, pid);

                            ReaderBean rb = new ReaderBean();
                            rb.setUserID(uid);
                            rb.setUserName(userName);
                            rb.setDeptID(deptID);
                            rb.setDeptName(departmentName);
                            rb.setPositionID(pid);
                            rb.setPositionName(positionName);

                            hm.put(new Integer(uid), rb);
                        }
                    } else if (userID != 0) {
                        String userName = users.getUserByID(userID).getUserName();
                        String departmentName =
                            ((BeanDepartment) departments.getDeptByID(deptID))
                                .getDepartmentName();

                        //log.error("开始取userID:" + userID + ",deptID:" + deptID + " 对应的positionID的值。");
                        int positionID = 0;
                        if (userID == 1) { //如果是系统管理员
                            positionID = 1; //直接设置其职务为代定
                        } else {
                            positionID = users.getUserPosition(userID, deptID);
                        }
                        //log.error("positionID:####" + positionID + "####");
                        String positionName = getPosition(positions, positionID);

                        ReaderBean rb = new ReaderBean();
                        rb.setUserID(userID);
                        rb.setUserName(userName);
                        rb.setDeptID(deptID);
                        rb.setDeptName(departmentName);
                        rb.setPositionID(positionID);
                        rb.setPositionName(positionName);

                        hm.put(new Integer(userID), rb);
                    }
                }
            }

            empList.addAll(hm.values());

            form.setEmpList(empList);
            form.setSelGroupID(selGroupID);
            form.setSelDeptID("9998");

            ArrayList readerList = new ArrayList();
            readerIDList = (ArrayList) session.getAttribute("readerIDList");
            if (readerIDList != null && readerIDList.size() > 0) {
                Iterator ior = readerIDList.iterator();

                while (ior.hasNext()) {
                    ReaderBean nrb = new ReaderBean();
                    String ids = (String) ior.next();
                    StringTokenizer st = new StringTokenizer(ids, "#");
                    int i = 0;
                    int userID = 0;
                    int deptID = 0;
                    int positionID = 0;
                    while (st.hasMoreTokens()) {
                        if (i == 0)
                            userID = Integer.parseInt((String) st.nextElement());
                        else if (i == 1)
                            deptID = Integer.parseInt((String) st.nextElement());
                        else if (i == 2)
                            positionID =
                                Integer.parseInt((String) st.nextElement());
                        i++;
                    }

                    String userName =
                        ((BeanUser) users.getUserByID(userID)).getUserName();
                    String deptName =
                        ((BeanDepartment) departments.getDeptByID(deptID))
                            .getDepartmentName();
                    String positionName = getPosition(positions, positionID);

                    nrb.setUserID(userID);
                    nrb.setUserName(userName);
                    nrb.setDeptID(deptID);
                    nrb.setDeptName(deptName);
                    nrb.setPositionID(positionID);
                    nrb.setPositionName(positionName);
                    readerList.add(nrb);
                }

                /*ArrayList readerNameList = new ArrayList();
                String tmpStr = (String)session.getAttribute("readerNameStr");
                if (tmpStr != null && !tmpStr.equals("")) {
                    StringTokenizer st = new StringTokenizer(tmpStr, "#");
                    while(st.hasMoreTokens()) {
                        readerNameList.add((String)st.nextElement());
                    }
                }
                Iterator ier = readerNameList.iterator();
                       
                while (ior.hasNext()) {
                    ReaderBean nrb = new ReaderBean();
                    int userID = Integer.parseInt((String)ior.next());
                    String readerStr = (String)ier.next();
               
                    StringTokenizer st = new StringTokenizer(readerStr, "&&&&&&&&");
                    if(st.hasMoreTokens()) {
                        nrb.setUserName((String)st.nextElement());
                        nrb.setDeptName((String)st.nextElement());
                    }
                    StringTokenizer st1 = new StringTokenizer((String)st.nextElement(), "&&");
                    if(st1.hasMoreTokens()) {
                        nrb.setPositionName((String)st1.nextElement());
                    }
               
                    nrb.setUserID(userID);
                    readerList.add(nrb);
                }*/
                form.setReaderList(readerList);
                form.setSelectedIDStr(null);
            } else {
                form.setReaderList(readerList);
                form.setSelectedIDStr(null);
            }

            return (mapping.findForward(FORWARD_Select));
    }
   
    /**
     *
     * @param mapping
     * @param form
     * @param request
     * @throws Exception
     * @return ActionForward
     */
    public ActionForward doSave(ActionMapping mapping,
                                SelectReaderForm form,
                                HttpServletRequest request,
                                HttpServletResponse response,
                                User user)
        throws Exception {

        // Add your logic code here
        HttpSession session = request.getSession();
        String readerNameStr = form.getReaderNameStr();
        session.removeAttribute("readerNameStr");
       
        setReaderID("ReaderIDs",mapping,form,request,response,user);
            session.removeAttribute("readerIDList");
        //}
       
        return (mapping.findForward(FORWARD_Back));
    }
     
    /**
     *
     * @param mapping
     * @param form
     * @param request
     * @throws Exception
     * @return ActionForward
     */
    public ActionForward doCancel(ActionMapping mapping,
                                SelectReaderForm form,
                                HttpServletRequest request,
                                HttpServletResponse response,
                                User user)
        throws Exception {

log.debug("enter save:");
        // Add your logic code here
        HttpSession session = request.getSession();
        String readerNameStr = form.getReaderNameStr();
        session.removeAttribute("readerNameStr");
       
        session.removeAttribute("readerIDList");
        form.reset();
       
       
        return (mapping.findForward(FORWARD_Back));
    }
     
//  add by weij; 
/**
*
* @param mapping
* @param form
* @param request
* @throws Exception
* @return ActionForward
*/
public ActionForward doSave2(ActionMapping mapping,
SelectReaderForm form,
HttpServletRequest request,
HttpServletResponse response,
User user)
throws Exception {

// Add your logic code here
HttpSession session = request.getSession();
String readerNameStr = form.getReaderNameStr();
session.removeAttribute("readerNameStr");
       
        setReaderID("ReaderIDs2",mapping,form,request,response,user);
        session.removeAttribute("readerIDList");
//}
       
return (mapping.findForward(FORWARD_Back));
}
       
    private String getPosition(CachePositions posts, int pid) {
        String position = DEFAULT_POSITION;
        BeanPosition bpost0 = (BeanPosition) posts.getPositionByID(pid);
        if (bpost0 != null) {
            position = bpost0.getPosition();
        }

        return position;
    }
   
    private boolean setReaderID(String attrName,
                                  ActionMapping mapping,
                                  SelectReaderForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response,
                                  User user)
    {
        String[] tmpIDArray = form.getSelectedIDStr();
      

        ArrayList readerIDList = new ArrayList();
        if (tmpIDArray != null) {
            for (int i = 0; i < tmpIDArray.length; i ++) {
                readerIDList.add(tmpIDArray[i]);
                log.debug("tmpIDArray[i]:"+tmpIDArray[i]);
            }
        }
       
        if (readerIDList != null && readerIDList.size() > 0) {
            ArrayList readerList = new ArrayList();
            Iterator ior = readerIDList.iterator();

            while (ior.hasNext()) {
                ReaderBean nrb = new ReaderBean();
                String ids = (String) ior.next();
                log.debug("ids: "+ids);
                StringTokenizer st = new StringTokenizer(ids, "#");
                log.debug("StringTokenizer:"+st.toString());
                int i = 0;
                int userID = 0;
                int deptID = 0;
                int positionID = 0;
                while (st.hasMoreTokens()) {
                    if (i == 0)
                        userID = Integer.parseInt((String) st.nextElement());
                    else if (i == 1)
                        deptID = Integer.parseInt((String) st.nextElement());
                    else if (i == 2)
                        positionID =
                            Integer.parseInt((String) st.nextElement());
                    ;
                    i++;
                }
                log.debug("userid:"+userID);
                readerList.add((new Integer(userID)).toString());

            }
            System.out.println("arrname:"+attrName);
            HttpSession session = request.getSession();
            session.setAttribute(attrName,readerList);
            if(readerList!=null)
System.out.println("readerList.size:"+readerList.size());
            else
System.out.println("readerList is null!!!");

        }
       
        return true;
       
    }


}

你可能感兴趣的:(Struts,Servlet,Apache,Bean)