1
2
3
4
5
6
7
8 package com.buckosoft.PicMan.web;
9
10 import java.util.HashMap;
11 import java.util.Map;
12
13 import javax.servlet.http.HttpServletRequest;
14 import javax.servlet.http.HttpServletResponse;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18 import org.springframework.validation.BindException;
19 import org.springframework.web.servlet.ModelAndView;
20
21 import com.buckosoft.BSAccount.web.BSAccountSimpleFormController;
22 import com.buckosoft.BSAccount.web.BSAccountUserWebSession;
23 import com.buckosoft.PicMan.business.PicManFacade;
24 import com.buckosoft.PicMan.domain.User;
25
26
27
28
29
30
31 public class UserConfigFormController extends BSAccountSimpleFormController {
32
33 private static final boolean DEBUG = true;
34 protected final Log logger = LogFactory.getLog(getClass());
35
36 private PicManFacade pmf;
37
38
39
40
41 public void setPicMan(PicManFacade pmf) { this.pmf = pmf; }
42
43 public UserConfigFormController() {
44 setSessionForm(true);
45 setValidateOnBinding(false);
46 setCommandName("userConfigForm");
47 setFormView("UserConfigForm");
48 }
49
50 protected Object formBackingObject(HttpServletRequest request) throws Exception {
51 BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request);
52 User user = null;
53 if (userWebSession != null)
54 user = (User)userWebSession.getUser();
55 if (DEBUG)
56 logger.info("formBackingObject session " + userWebSession);
57 UserConfigForm ucf = new UserConfigForm();
58
59 ucf.setUserWebSession(userWebSession);
60 ucf.setUser(user);
61 ucf.setSets(pmf.getDB().getSets());
62
63 return(ucf);
64 }
65
66 protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors)
67 throws Exception {
68 if (DEBUG)
69 logger.info("onBindAndValidate");
70 UserConfigForm ucf = (UserConfigForm) command;
71 User user = ucf.getUser();
72 if (request.getParameter("user.picBrowserShowRatings") == null)
73 user.setPicBrowserShowRatings(false);
74 if (request.getParameter("user.homeDebug") == null)
75 user.setHomeDebug(false);
76 }
77
78 protected Map<String, Object> referenceData(HttpServletRequest request) throws Exception {
79 BSAccountUserWebSession userWebSession = this.bsAccountMan.getUserWebSession(request);
80 Map<String, Object> myModel = new HashMap<String, Object>();
81 myModel.put("userWebSession", userWebSession);
82 if (DEBUG)
83 logger.info("referenceData session " + userWebSession);
84
85 return myModel;
86 }
87
88 protected ModelAndView onSubmit(
89 HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
90 throws Exception {
91 boolean success = true;
92 response.sendRedirect("home.do");
93
94 UserConfigForm ucf = (UserConfigForm) command;
95 pmf.getDB().storeUser(ucf.getUser());
96
97 if (success) {
98 return(null);
99 }
100 else
101 return super.onSubmit(request, response, command, errors);
102 }
103 }