Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tiles and redirect in Spring MVC

I am using Tiles 2 in my Spring 3 MVC application i defines a form :

     <definition name="addcompany.htm" extends="baseLayout">
      <put-attribute name="title"  value="Add Company"/>
      <put-attribute name="body"   value="/WEB-INF/jsp/addcompany.jsp"/>      
  </definition>

and :

addcompany.(class)=org.springframework.web.servlet.view.tiles2.TilesView
addcompany.url=addcompany.htm

And here is my controller :

@RequestMapping(value="/addcompany.htm", method=RequestMethod.GET)
public ModelAndView getForm() {
    logger.info("Getting form!");
    ModelAndView mav = new ModelAndView();
    logger.info("Loading form");
    Company cmp = new Company();
    mav.addObject("company",cmp);
    mav.setViewName("addcompany");
    return mav;
}

@RequestMapping(value="/addcompany.htm", method=RequestMethod.POST)
public String  postForm(@ModelAttribute("company") Company cmp) {
    logger.info("post form!");
    companyService.saveCompany(cmp);
    logger.info("post form");
    return "redirect:tiles:companylist"; // How do i redirect?
}

Using Tiles2, the REDIRECT doesnt work.

Any idea how to redirect after a successful POST using Tiles ?

thanks

EDIT : Solution is to add this in the views.properties :

redirectcompanylist.(class)=org.springframework.web.servlet.view.RedirectView
redirectcompanylist.url=/companylist.htm

And return redirectcompanylist in the controller

like image 837
guigui42 Avatar asked Nov 17 '10 22:11

guigui42


1 Answers

You'll have to use the URL path when redirecting. Like this: return redirect:/companylist.htm which then goes to the corresponding method in the controller.

like image 135
hleinone Avatar answered Sep 25 '22 13:09

hleinone