/*
 * Copyright 2002-2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/
package anyframe.sample.springmvc.web.controller.extensions;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import anyframe.sample.springmvc.services.UserService;
import anyframe.sample.springmvc.services.UserVO;
import anyframe.web.springmvc.controller.AnyframeFormController;

/**
 * This is sample code for controller class what extends
 * AbstractCommandController.
 * 
 * @author Heewon Jung
 * 
 */
public class UserController extends AnyframeFormController {

	UserService userService = null;

	// setter injection of userSerivce
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	public UserController() {
		setCommandClass(UserVO.class);
		setCommandName("users");
	}

	// override onSubmit() method.
	public ModelAndView getUser(HttpServletRequest request, HttpServletResponse response) throws Exception {

		UserVO userVO = new UserVO();
		// data binding using command object
		bind(request,userVO);

		// call business service
		userVO = userService.getUser(userVO);
		// setting view name
		ModelAndView mav = new ModelAndView(this.getSuccess_get());
		mav.addObject(userVO);
		
		// return a ModelAndView object.
		return mav;
	}

	protected Object formBackingObject(HttpServletRequest request)
			throws Exception {
		Map address = new HashMap();
		address.put("seoul", "서울");
		address.put("daegu", "대구");
		address.put("busan", "부산");

		Map hobby = new HashMap();
		hobby.put("reading", "독서");
		hobby.put("listeningMusic", "음악감상");
		hobby.put("study", "공부");
		
		request.setAttribute("address", address);
		request.setAttribute("hobby", hobby);
		return new UserVO();
	}

}

