1 /**************************************************************************
2 Copyright 2005 Webstersmalley
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 *************************************************************************/
16
17
18
19 package com.webstersmalley.picweb.online.web;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import javax.servlet.ServletException;
25 import javax.servlet.http.HttpServletRequest;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.springframework.web.servlet.ModelAndView;
30 import org.springframework.web.servlet.mvc.SimpleFormController;
31 import org.springframework.web.servlet.view.RedirectView;
32
33 import com.webstersmalley.picweb.online.bus.Category;
34 import com.webstersmalley.picweb.online.bus.CategoryManager;
35
36 public class CategoryAdminFormController extends SimpleFormController {
37 /*** Logger for this class and subclasses */
38 protected final Log logger = LogFactory.getLog(getClass());
39
40 private CategoryManager categoryManager;
41
42 public ModelAndView onSubmit(Object command) throws ServletException {
43 Category category = (Category) command;
44 logger.info("adding " + category.getName() + "("
45 + category.getDescription() + ")");
46 categoryManager.createAndStoreCategory(category);
47 Map myModel = new HashMap();
48 myModel.put("category", category);
49 return new ModelAndView(new RedirectView(getSuccessView()));
50 }
51
52 protected Object formBackingObject(HttpServletRequest request)
53 throws ServletException {
54 Category category = new Category();
55 category.setName("The new name");
56 category.setDescription("The new description");
57 return category;
58
59 }
60
61 /***
62 * @return Returns the categoryManager.
63 */
64 public CategoryManager getCategoryManager() {
65 return categoryManager;
66 }
67
68 /***
69 * @param categoryManager
70 * The categoryManager to set.
71 */
72 public void setCategoryManager(CategoryManager categoryManager) {
73 this.categoryManager = categoryManager;
74 }
75
76 }