views:

48

answers:

0

I have two reports. A master report named report1.jrsml show id from table student and a subreport named abc.jrsml show data from table studentfile.

Table Student alt text

Table Studentfile alt text

I use data source expression, when I run on webserver and invoke report from web application I have a result like this Image alt text .

It's wrong!

I would like to show subreport data. Please help me solve that.

this is code in servlet:

public class ReporPdfDataByHibernateController extends AbstractController {

JasperPrint JPrint=null;
Transaction transaction = null;
Session session=null;
protected ModelAndView handleRequestInternal(
        HttpServletRequest request, HttpServletResponse res)throws Exception{

    ModelAndView mav = null;
    JasperPrint JPrint;
    int cid = Integer.parseInt(request.getParameter("cid"));

    try{    String source2 = (new StringBuilder(String.valueOf(realPath(request)))).append("/WEB-INF/reports/").toString();
        //  String source = (new StringBuilder(String.valueOf(realPath(request)))).append("/WEB-INF/reports/report1.jrxml").toString();

            HibernateUtil hibernateUtil = new HibernateUtil();
            session = hibernateUtil.getSessionFactory().openSession();

            Function ft = new Function();
            List<Student> listStudent = ft.listCourse(session);                                                             
            Map<String,Object> parameterMap = new HashMap<String,Object>();                                                 

            List ltf = ft.listStudentfile(session);

            JRAbstractBeanDataSource jRBeanCollectionDataSource = new JRBeanCollectionDataSource(listStudent);
            JRDataSource jRBeanCollectionDataSource2 = new JRBeanCollectionDataSource(ltf);                 
            JRMapCollectionDataSource jj = new JRMapCollectionDataSource(ltf);


        parameterMap.put("SUBREPORT_DIR",source2);
        parameterMap.put("report1", jRBeanCollectionDataSource);            
        parameterMap.put("abc",jRBeanCollectionDataSource2);


        mav = new ModelAndView("reporpdfdatabyhibernate",parameterMap);         
    }
    catch(Exception e){                 
        e.printStackTrace();
    }finally
    {           
            session.close();        
    }   
    return mav;
}
public static String realPath(HttpServletRequest request)
{       
    String catalinaHome = System.getProperty("catalina.home");
    String realPath = catalinaHome + "/webapps" + request.getContextPath();

    return realPath;
}

} // abc is parameter with type net.sf.jasperreports.engine.JRDataSource in ireport // datasource expression use $P{abc}