KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > admin > action > category > AddCategoryAction


1 package org.nextime.ion.admin.action.category;
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.*;
14 import org.nextime.ion.framework.business.Group;
15 import org.nextime.ion.framework.business.*;
16 import org.nextime.ion.framework.mapping.Mapping;
17
18 public class AddCategoryAction 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", "category");
29
30         String JavaDoc id = "";
31
32         try {
33                         
34             // si on a pas soumis le formulaire
35
if (request.getParameter("addSubmit") == null)
36                 return new ActionForward( mapping.getInput() );
37
38             // creation de l'objet
39
CategoryForm f = (CategoryForm) form;
40             Mapping.begin();
41             id = f.getId();
42             Category u = Category.create(f.getId());
43             Mapping.commit();
44
45         } catch (Exception JavaDoc e) {
46             Mapping.rollback();
47             request.setAttribute("error", e.getMessage());
48             return new ActionForward( mapping.getInput() );
49         }
50         
51         // on va passer l'id en request pour aller directement
52
// la page d'edition
53
request.setAttribute("id", id);
54         
55         return mapping.findForward("success");
56     }
57
58 }
Popular Tags