views:

154

answers:

1

Hi,

I have the following problem. I need to export a PDF in a controller

The code below, where I return a 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 a 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, the 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 appreciated.

Thanks.

+2  A: 

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

Thanks anyway for your feedback.

adancu
I've done that myself more than once, it's a pain in the ass, which is why I explicitly remove the portlet stuff from the Spring libs when developing.
skaffman
I'd upvote you 100x if I could. I spent nearly 2 days trying to imagine every possible scenario as to why none of my model variables were showing up in my view.
Jason Nichols