KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xpetstore > web > struts > action > customer > CreateCustomerAction


1 package xpetstore.web.struts.action.customer;
2
3 import javax.servlet.http.HttpServletRequest JavaDoc;
4 import javax.servlet.http.HttpServletResponse JavaDoc;
5
6 import org.apache.struts.action.ActionForm;
7 import org.apache.struts.action.ActionForward;
8 import org.apache.struts.action.ActionMapping;
9
10 import xpetstore.domain.customer.ejb.Customer;
11
12 import xpetstore.services.petstore.exceptions.DuplicateAccountException;
13 import xpetstore.services.petstore.exceptions.DuplicateEmailException;
14
15 import xpetstore.web.struts.action.BaseAction;
16
17
18 /**
19  * @author <a HREF="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
20  *
21  * @struts.action
22  * name="customerForm"
23  * path="/createCustomer"
24  * scope="request"
25  * validate="true"
26  * input="/register.jsp"
27  *
28  * @struts.action-forward
29  * name="success"
30  * path="/signon.jspa"
31  *
32  * @struts.action-forward
33  * name="error"
34  * path="/register.jsp"
35  */

36 public class CreateCustomerAction
37     extends BaseAction
38 {
39     //~ Methods ----------------------------------------------------------------
40

41     /**
42      * @see xpetstore.web.struts.action.BaseAction#doExecute(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse)
43      */

44     protected ActionForward doExecute( ActionMapping mapping,
45                                        ActionForm form,
46                                        HttpServletRequest JavaDoc request,
47                                        HttpServletResponse JavaDoc response )
48         throws Exception JavaDoc
49     {
50         CustomerForm frm = ( CustomerForm ) form;
51         Customer cust = frm.getCustomer( );
52
53         try
54         {
55             getPetstore( ).createCustomer( cust );
56             return mapping.findForward( SUCCESS );
57         }
58         catch ( DuplicateAccountException da )
59         {
60             request.setAttribute( MESSAGE_KEY, "duplicate_account" );
61
62             return mapping.findForward( ERROR );
63         }
64         catch ( DuplicateEmailException de )
65         {
66             request.setAttribute( MESSAGE_KEY, "duplicate_email" );
67
68             return mapping.findForward( ERROR );
69         }
70     }
71 }
72
Popular Tags