KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > samples > jpetstore > web > struts > NewOrderFormAction


1 package org.springframework.samples.jpetstore.web.struts;
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 org.springframework.samples.jpetstore.domain.Account;
11
12 public class NewOrderFormAction extends SecureBaseAction {
13
14   protected ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
15     AccountActionForm acctForm = (AccountActionForm) request.getSession().getAttribute("accountForm");
16     CartActionForm cartForm = (CartActionForm) request.getSession().getAttribute("cartForm");
17     if (cartForm != null) {
18       OrderActionForm orderForm = (OrderActionForm) form;
19       // Re-read account from DB at team's request.
20
Account account = getPetStore().getAccount(acctForm.getAccount().getUsername());
21       orderForm.getOrder().initOrder(account, cartForm.getCart());
22       return mapping.findForward("success");
23     }
24         else {
25       request.setAttribute("message", "An order could not be created because a cart could not be found.");
26       return mapping.findForward("failure");
27     }
28   }
29
30 }
Popular Tags