The view does not appear when ModelAndView returns

I have the following problem. I need to export a pdf file to the controller

The code below, where I return the view, works as expected.


@RequestMapping(method = RequestMethod.GET)
    public View exportReport(
            @RequestParam(value = "userName", required = true) String userName,
            @RequestParam(value = "startDate", required = true) Date startDate,
            @RequestParam(value = "endDate", required = true) Date endDate) {


                ///////////////////////////////////////////

        return new TimeSheetReportPdfView();
    }

The problem occurs if I change the method to return ModelAndView:


@RequestMapping(method = RequestMethod.GET)
    public ModelAndView exportReport(
            @RequestParam(value = "userName", required = true) String userName,
            @RequestParam(value = "startDate", required = true) Date startDate,
            @RequestParam(value = "endDate", required = true) Date endDate) {


                ///////////////////////////////////////////

        return new ModelAndView(new TimeSheetReportPdfView(), model);
    }

Now PDF is not exported, all I get is a blank page and nothing in the logs.

Update:


public class TimeSheetReportPdfView extends AbstractPdfView {   

    @SuppressWarnings("unchecked")
    @Override
    protected void buildPdfDocument(Map model, Document document,
            PdfWriter writer, HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        }

Any help was appreciated.

Thank.

+3
source share
1 answer

Well, I found the reason for this behavior. Apparently, when I imported ModelAndView, I accidentally imported it from org.springframework.web.portlet instead of org.springframework.web.servlet.

Thanks for your feedback.

+6
source

Source: https://habr.com/ru/post/1739581/


All Articles