KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > admin > action > group > AddGroupAction


1 package org.nextime.ion.admin.action.group;
2
3 import java.io.IOException JavaDoc;
4
5 import javax.servlet.ServletException JavaDoc;
6 import javax.servlet.http.HttpServletRequest JavaDoc;
7 import javax.servlet.http.HttpServletResponse JavaDoc;
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.GroupForm;
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 AddGroupAction extends Action {
19
20     public ActionForward perform(
21         ActionMapping mapping,
22         ActionForm form,
23         HttpServletRequest JavaDoc request,
24         HttpServletResponse JavaDoc response)
25         throws IOException JavaDoc, ServletException JavaDoc {
26
27         // pour situer la vue
28
request.setAttribute("view", "group");
29
30         String JavaDoc id = "";
31
32         try {
33
34             // pour remplir les listes select
35
Mapping.begin();
36             request.setAttribute("userList", User.listAll());
37             Mapping.commit();
38
39             // si on a pas soumis le formulaire
40
if (request.getParameter("addSubmit") == null)
41                 return new ActionForward( mapping.getInput() );
42
43             // creation de l'objet
44
GroupForm f = (GroupForm) form;
45             Mapping.begin();
46             id = f.getId();
47             Group u = Group.create(f.getId());
48             String JavaDoc[] g = f.getUsers();
49             if (g != null) {
50                 for (int i = 0; i < g.length; i++) {
51                     u.addUser(User.getInstance(g[i]));
52                 }
53             }
54             Mapping.commit();
55
56         } catch (Exception JavaDoc e) {
57             Mapping.rollback();
58             request.setAttribute("error", e.getMessage());
59             return new ActionForward( mapping.getInput() );
60         }
61         
62         // on va passer l'id en request pour aller directement
63
// la page d'edition
64
request.setAttribute("id", id);
65         
66         return mapping.findForward("success");
67     }
68
69 }
Popular Tags