1 package org.nextime.ion.admin.action.user; 2 3 import java.io.IOException ; 4 5 import javax.servlet.ServletException ; 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 8 import org.apache.struts.action.Action; 9 import org.apache.struts.action.ActionForm; 10 import org.apache.struts.action.ActionForward; 11 import org.apache.struts.action.ActionMapping; 12 13 import org.nextime.ion.admin.form.UserForm; 14 import org.nextime.ion.framework.business.Group; 15 import org.nextime.ion.framework.business.User; 16 import org.nextime.ion.framework.mapping.Mapping; 17 18 public class AddUserAction extends Action { 19 20 public ActionForward perform( 21 ActionMapping mapping, 22 ActionForm form, 23 HttpServletRequest request, 24 HttpServletResponse response) 25 throws IOException , ServletException { 26 27 request.setAttribute("view", "user"); 29 30 String id = ""; 31 32 try { 33 34 Mapping.begin(); 36 request.setAttribute("groupList", Group.listAll()); 37 Mapping.commit(); 38 39 if (request.getParameter("addSubmit") == null) 41 return new ActionForward( mapping.getInput() ); 42 43 UserForm f = (UserForm) form; 45 Mapping.begin(); 46 id = f.getLogin(); 47 User u = User.create(f.getLogin()); 48 u.setPassword(f.getPassword()); 49 String [] g = f.getGroups(); 50 if (g != null) { 51 for (int i = 0; i < g.length; i++) { 52 u.addGroup(Group.getInstance(g[i])); 53 } 54 } 55 Mapping.commit(); 56 57 } catch (Exception e) { 58 Mapping.rollback(); 59 request.setAttribute("error", e.getMessage()); 60 return new ActionForward( mapping.getInput() ); 61 } 62 63 request.setAttribute("id", id); 66 67 return mapping.findForward("success"); 68 } 69 70 } | Popular Tags |