Source Code Cross Referenced for ShoppingCartController.java in  » J2EE » JOnAS-4.8.6 » olstore » controller » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » olstore.controller 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (c) 2006 Red Hat, Inc. All rights reserved.
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
017:         * USA
018:         *
019:         * Component of: Red Hat Application Server
020:         * 
021:         * Initial Developers: Greg Lapouchnian
022:         *                     Patrick Smith
023:         *
024:         */package olstore.controller;
025:
026:        import java.util.Iterator;
027:        import java.util.Map;
028:
029:        import javax.servlet.http.HttpServletRequest;
030:        import javax.servlet.http.HttpServletResponse;
031:
032:        import olstore.domain.logic.OlstoreFacade;
033:        import olstore.domain.manager.CartManager;
034:        import olstore.dto.ShoppingCartItem;
035:
036:        import org.springframework.web.servlet.ModelAndView;
037:        import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
038:
039:        /**
040:         * A controller that handles shopping cart related actions.
041:         */
042:        public class ShoppingCartController extends MultiActionController {
043:
044:            // The olstore instance provided via Spring.
045:            private OlstoreFacade olstore;
046:
047:            /**
048:             * The Spring injection setter method for the olstore instance.
049:             * @param olstore the instance provided via spring.
050:             */
051:            public void setOlstore(OlstoreFacade olstore) {
052:                this .olstore = olstore;
053:            }
054:
055:            /**
056:             * Returns a new model and view for this controller. 
057:             * @param request the HttpServletRequest
058:             * @param response the HttpServletResponse
059:             * @return a new model and view that represents the data for this controller.
060:             * @throws Exception
061:             */
062:            public ModelAndView view(HttpServletRequest request,
063:                    HttpServletResponse response) throws Exception {
064:
065:                Map model = ControllerHelper.initModel(request, olstore);
066:                CartManager cartManager = (CartManager) request.getSession()
067:                        .getAttribute("cart");
068:
069:                model.put("items", cartManager.getItems());
070:
071:                request.setAttribute("page_title",
072:                        "Shopping Cart Contents  - Olstore");
073:                return new ModelAndView("cart", model);
074:            }
075:
076:            /**
077:             * Called when we are in an update cart action.
078:             * @param request the HttpServletRequest.
079:             * @param response the HttpServletResponse.
080:             * @return a model and view for representing the updating of a cart.
081:             * @throws Exception
082:             */
083:            public ModelAndView update(HttpServletRequest request,
084:                    HttpServletResponse response) throws Exception {
085:                Map model = ControllerHelper.initModel(request, olstore);
086:                CartManager cartManager = (CartManager) request.getSession()
087:                        .getAttribute("cart");
088:                model.put("items", cartManager.getItems());
089:                request.setAttribute("page_title",
090:                        "Shopping Cart Contents - Olstore");
091:
092:                Iterator i = cartManager.getItems().iterator();
093:                while (i.hasNext()) {
094:                    int itemId = ((ShoppingCartItem) i.next()).getItemId()
095:                            .intValue();
096:                    int quantity;
097:                    try {
098:                        quantity = Integer.valueOf(
099:                                request.getParameter(String.valueOf(itemId)))
100:                                .intValue();
101:                        cartManager.updateQuantity(new Integer(itemId),
102:                                new Integer(quantity));
103:                    } catch (NumberFormatException e) {
104:                        model.put("error", "Quantity invalid. Smarten-up.");
105:                    }
106:                }
107:                return new ModelAndView("cart", model);
108:            }
109:
110:            /**
111:             * Called when we are performing an order action.
112:             * @param request the HttpServletRequest.
113:             * @param response the HttpServletResponse.
114:             * @return a model and view to represent the updating order.
115:             * @throws Exception
116:             */
117:            public ModelAndView order(HttpServletRequest request,
118:                    HttpServletResponse response) throws Exception {
119:                Map model = ControllerHelper.initModel(request, olstore);
120:                CartManager cartManager = (CartManager) request.getSession()
121:                        .getAttribute("cart");
122:
123:                cartManager.placeOrder();
124:
125:                model.put("page_title", "Shopping Cart Contents - Olstore");
126:                model
127:                        .put("message",
128:                                "Your order has been placed. Thank you for shopping with us.");
129:
130:                return new ModelAndView("cart", model);
131:            }
132:
133:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.