Nested @RequestMapping - how it works in Apache Tiles view?

426 views Asked by At

I am using Spring and Apache Tiles (to manage my views). I have Controller class:

@Controller
@RequestMapping("/insurancecompany")
public class InsuranceCompanyController {

    @Autowired
    private InsuranceCompanyService insuranceCompanyService;

    @RequestMapping("/create")
    public ModelAndView createInsuranceCompany() {
        ModelAndView mv = new ModelAndView();
        mv.addObject("insuranceCompany", new InsuranceCompany());
        return mv;
    }

What should I write into Apache Tiles xml file to make it work? My xml file

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">

<tiles-definitions>

    <definition name="main.template" template="/WEB-INF/templates/maintemplate.jsp">
        <put-attribute name="title" value="Welcome on my web app" />
        <put-attribute name="menu" value="/WEB-INF/tiles/menu.jsp" />
        <put-attribute name="body" value="" />
    </definition>
    ...
    <definition name="WHAT SHOULD BE HERE??" extends="main.template">
        <put-attribute name="title" value="Insurance Company" />
        <put-attribute name="body" value="/WEB-INF/tiles/createinsurancecompany.jsp" />
    </definition>

</tiles-definitions>
2

There are 2 answers

0
mpj On BEST ANSWER

I changed my controller class. I replace return type of my createInsuranceCompany method and now it returns String (unique name which is used in apache tiles xml file)

@Controller
@RequestMapping("/insurancecompany")
public class InsuranceCompanyController {

    @Autowired
    private InsuranceCompanyService insuranceCompanyService;

    @RequestMapping("/create")
    public String createInsuranceCompany(Model model) {
        model.addAttribute("insuranceCompany", new InsuranceCompany());
        return "insurancecompany-create";
    }
}

And my apache xml file looks like this

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">

<tiles-definitions>

    <definition name="main.template" template="/WEB-INF/templates/maintemplate.jsp">
        <put-attribute name="title" value="Welcome on my web app" />
        <put-attribute name="menu" value="/WEB-INF/tiles/menu.jsp" />
        <put-attribute name="body" value="" />
    </definition>

    ...

    <definition name="insurancecompany-create" extends="main.template">
        <put-attribute name="title" value="Insurance Company" />
        <put-attribute name="body" value="/WEB-INF/tiles/createinsurancecompany.jsp" />
    </definition>

</tiles-definitions>
0
Ralph On

The view name of the returned ModelAndView is insuranceCompany

 mv.addObject("insuranceCompany" ...

so the tiles name is insuranceCompany too. (without any slash and uppercase "C")