Results 1 to 9 of 9

Thread: Redirect to new controller method does not change url

Threaded View

  1. #1
    Join Date
    Apr 2012
    Posts
    13

    Question Redirect to new controller method does not change url

    hi there, this is my first post...

    i'm new to spring and i'm stuck in a little problem...

    I've a controller with 3 methods like these:
    Code:
    @RequestMapping(value = {"","/list"}, method = RequestMethod.GET)
    	public MyModelAndView getCustomerList() {
    		MyModelAndView mav = new MyModelAndView();
    		mav.setViewName("default");
    		mav.addObject("component", "customers");
    		mav.addObject("pageTitle", "Customers Management");
    		mav.addObject("page", "index");
    		
    		List<Customer> customersList = customerBo.list();
    		mav.addObject("customersList",customersList);
    
    		return mav;
    	}
    
    @RequestMapping(value = "/new", method = RequestMethod.GET)
    	public MyModelAndView newCustomer() {
    		MyModelAndView mav = new MyModelAndView();
    		mav.setViewName("default");
    		mav.addObject("component", "customers");
    		mav.addObject("pageTitle", "New Customer");
    		mav.addObject("page", "customer");
    
    		mav.addObject("customer", new Customer());
    
    		return mav;
    	}
    
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    	public MyModelAndView saveCustomer(@Valid Customer customer, BindingResult result) {
    		if (result.hasErrors()) {
    			Message errorMessage = new Message();
    			errorMessage.setType(MessageType.MESSAGE_ERR);
    
    			for (ObjectError err : result.getAllErrors()) {
    				errorMessage.addText(err.getDefaultMessage());
    			}
    
    			MyModelAndView mav = newCustomer();
    
    			mav.addObject(MessageType.MESSAGE_ERR.getType(), errorMessage);
    			mav.addObject("customer", customer);
    
    			return mav;
    		} else {
    			customerBo.save(customer);
    			return getCustomerList();
    		}
    
    	}
    When i go to "/" or "/list" getCustomerList() is called and i got the list of the customers;
    in this page i've a button that point to /new and that brings me to the new customer form.
    Now the problem....when i save the form I validate the bean, in case of success I persist the object and then I return the getCustomerList() method, but, while the view changes, the url in the browser remains "/save"...

    I'd like to display "/" or "/list"...
    how can i do it?

    thanks
    Last edited by fsteccanella; Apr 4th, 2012 at 02:58 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •