GobyDot
GobyDot

Reputation: 483

Why I do get "Value [null] cannot be converted to a JRDataSource" exception

i'm trying to calculate number of admissions for particular year range input

but why I do get this exception (Checked a few existing answers but couldn't figure it out.)

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Value [null] cannot be converted to a JRDataSource

This is my controller

@RequestMapping(value ="/BMIbyage",method = RequestMethod.GET)
public ModelAndView BMIbyage(ModelAndView modelAndView, ModelMap model, Map<String, Object> map,HttpServletRequest request,
        @RequestParam("syear") int syear,@RequestParam("eyear") int eyear,HttpSession session){
    String childid = (String) session.getAttribute("childid");


    List<AdmissionSummery> asum = new ArrayList<AdmissionSummery>();

     List<PatientDetails> patientdetail = patientService.listpatient();

    for(int i=syear;i<=eyear;i++){
         asum.add(new AdmissionSummery());
        int no=0;
        for(int j=0;j<patientdetail.size();j++){


            float bmi = patientService.listPatient(patientdetail.get(j).getChildid()).get(0).getBmi();


            if(bmi<18.5){
                no=no+1;

                asum.get(asum.size()-1).setNooftime(no);

            }
            System.out.println("no"+no);
            System.out.println("j"+j);
            asum.get(asum.size()-1).setDuration(syear+" "+"-"+" "+eyear);
            asum.get(asum.size()-1).setYear(i);

            System.out.println("BMI"+bmi);

        }



        System.out.println("i"+i);
    }

      JRDataSource datasource = new JRBeanCollectionDataSource(asum);   

        model.addAttribute("datasourcebmireportA", datasource);

        model.addAttribute("format", "pdf");

        modelAndView = new ModelAndView("pdfReportViewaddsummeryA", model);



    return modelAndView;


}

here is the jsp

<tr>
    <td  ><a href="#"><div class="box">
        <form action="BMIbyage">
        <table width="584">
        <tr>
        <td width="172">
        <font color="black">BMI value  18.5kg/m2</font></td>
        <td width="82">
    <select name="syear"> 
    <option value="Pleaseselect">----</option>
                <%for(int j=1980;j<=2030;j++)
                {
                    %>
                    <option value="<%=j%>"><%=j%></option>
                    <%
                    }
                    %>
    </select>
    </td>
    <td width="20"> to </td>

    <td width="178">
    <select name="eyear"> 
    <option value="Pleaseselect">----</option>
                <%for(int j=1980;j<=2030;j++)
                {
                    %>
                    <option value="<%=j%>"><%=j%></option>
                    <%
                    }
                    %>
    </select>
    </td>
    <td width="108"><input type="submit" value="Generate"></td>
    </tr>
    </table>
        </form>

    </div></a></td>
    </tr>

and this is the jasper-views.xml

<bean id="pdfReportViewaddsummeryA" class="org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView" p:url="/WEB-INF/Reports/BMIReport.jasper" p:reportDataKey="datasourceadmissionreportA" />

Upvotes: 1

Views: 2407

Answers (1)

user20432
user20432

Reputation: 107

problem with your jasper-views.xml change

<bean id="pdfReportViewaddsummeryA" class="org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView" p:url="/WEB-INF/Reports/BMIReport.jasper" p:reportDataKey="datasourcebmireportA" />

instead of

<bean id="pdfReportViewaddsummeryA" class="org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView" p:url="/WEB-INF/Reports/BMIReport.jasper" p:reportDataKey="datasourceadmissionreportA" />

Upvotes: 1

Related Questions