日期:2014-05-17 浏览次数:20850 次
//部门与员工的doubleselect public Map<Department, List<User>> getDepUser() { db=DBConnectionManager.getInstance(); con=db.getConnection("idb"); sql="select departmentcode,departmentname from tb_department order by departmentcode"; //ArrayList listDepUser=new ArrayList(); Map<Department,List<User>> mapDepUser=new HashMap<Department,List<User>>(); try { ps=con.prepareStatement(sql); rs=ps.executeQuery(); while(rs.next()){ Department department=new Department(); department.setDepartmentcode(rs.getString("departmentcode")); department.setDepartmentname(rs.getString("departmentname")); sql2="select userid,username from tb_user where departmentcode='"+rs.getString("departmentcode")+"'"; ps=con.prepareStatement(sql2); rs1=ps.executeQuery(); List<User> uList=new ArrayList<User>(); while(rs1.next()) { //List<User> uList=new ArrayList<User>(); User user=new User(); user.setUserid(rs1.getString("userid")); user.setUsername(rs1.getString("username")); uList.add(user); //mapDepUser.put(department, uList); } mapDepUser.put(department, uList); } }catch(SQLException ex) { ex.printStackTrace(); }finally { freeCon(); } //listDepUser.addAll(mapDepUser.values()); return mapDepUser; }
private Map<Department, List<User>> coldepuser; public void setColdepuser(Map<Department, List<User>> coldepuser) { this.coldepuser=coldepuser; } public Map<Department, List<User>> getColdepuser() { return coldepuser; } //跳转到部门添加页面 public String add() throws Exception { //HttpServletRequest request=ServletActionContext.getRequest(); UserDao userdao=new UserDao(); //Map<Department,List<User>> mapDepUser=new HashMap<Department,List<User>>(); DepartmentDao departmentdao=new DepartmentDao(); Map<Department, List<User>> colDepUser=userdao.getDepUser(); Collection departmentcodeCol=departmentdao.getDepartmentCode(); setDepartmentcode(departmentcodeCol); setColdepuser(colDepUser); //request.setAttribute("mapDepUser", mapDepUser); return "add"; }
<p> <label>上级主管:</label> <s:doubleselect name="department.higherhead" list="coldepuser" listKey="departmentcode" listValue="departmentname" doubleList="coldepuser[top]" doubleName="userid" doubleListKey="userid" doubleListValue="username" theme="simple" /> </p>