2014-02-08 4 views
0

В моем файле xhtml мне нужно передать значение employeeId и employeeName из p: dialog в отчет jasper. Я уже создал jrxml (файл), поля - $ F {employeeId} и $ F {usageementName}. Когда я выбираю кнопку команды, она должна передавать employeeId и employeeName в отчет jasper и генерировать как .pdf. Но я не знаю, как передать employeeId и employeeName в JRBeanCollectionDataSource.как передать значения bean в отчет jasper

 <p:dialog header="Employee Details" widgetVar="actDialog" appendToBody="false" 
       resizable="false" showEffect="explode" hideEffect="explode"> 

       <h:panelGrid id="dialog" columns="2" cellpadding="4"> 

        <h:outputText value="Employee Id:" /> 
        <h:outputText 
         value="#{employeeBean.current.employeeId}" 
         style="font-weight:bold" /> 

        <h:outputText value="Employee Name:" /> 
        <h:outputText 
         value="#{employeeBean.current.employeeName}" 
         style="font-weight:bold" /> 

       </h:panelGrid> 
      <p:commandButton value="Report" ajax="false" icon="ui-icon-check" style="width:70px;" action="#{employeeBean.generateReport}"/> 
      </p:dialog> 

Bean:

private List<EmployementScheduleDTO> userList; 
    private EmployementScheduleDTO current; 

    public List<EmployementScheduleDTO> getUserList() { 
    return userList; 
    } 

    public void setUserList(List<EmployementScheduleDTO> userList) { 
    this.userList = userList; 
    } 

    public EmployementScheduleDTO getCurrent() { 
    return current; 
    } 

    public void setCurrent(EmployementScheduleDTO current) { 
    if (current != null) { 
     this.current = current; 
    } 
    } 

    public void generateReport() 
    { 
    reportGeneration(current, userList); 
    } 


    public void reportGeneration(EmployementScheduleDTO employeedto,List<EmployementScheduleDTO> a_beanList) 
    { 
    try 
     { 
      URL url = getClass().getClassLoader().getResource("/WEB-INF/reports/employee.jrxml"); 
      JasperReport jasperReport = JasperCompileManager.compileReport(url.getPath()); 
      JRBeanCollectionDataSource jrDataSource = 
      new JRBeanCollectionDataSource(a_beanList); 
      JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, jrDataSource); 

     } 
     catch (JRException jre) 
     { 
      jre.printStackTrace(); 
     } 
    catch(UnsupportedEncodingException e) 
    { 
     e.printStackTrace(); 
    } 

    } 
+0

Предполагая, что 'ток 'держит ссылку на члена' userList', я не понимаю, почему это не работает. Не могли бы вы привести примеры фактических и ожидаемых результатов? – GenericJon

ответ

0

Наконец я нашел значение ответа перейти от боба Джаспер report.Thank вас для тех, кто ответит мне ...

public EmployeeBean report(String empid,String empname) 
{ 
    EmployeeBean empbean=new EmployeeBean(); 
    empbean.setEmployeeId(empid); 
    empbean.setEmployeeName(empname); 
    return empbean; 
} 

public void init() throws JRException 
{ 

    String employeeid=current.getEmployeeId(); 
    String employeename=current.getEmployeeName(); 
    ArrayList<EmployeeBean> databeanlist=new ArrayList<EmployeeBean>(); 
    databeanlist.add(report(employeeid, employeename)); 
    JRBeanCollectionDataSource beancollection=new JRBeanCollectionDataSource(databeanlist); 
    String realpath=FacesContext.getCurrentInstance().getExternalContext().getRealPath("common/reports/jasperreport.jasper"); 
    jasperprint=JasperFillManager.fillReport(realpath, new HashMap(),beancollection); 
} 

public void generateReport() throws JRException, IOException 
{ 
    logger.info("enter into generate report"); 
    init(); 
    HttpServletResponse httpservlet=(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse(); 
    httpservlet.addHeader("Content-disposition", "attachment;filename=schedule.pdf"); 
    ServletOutputStream servletout=httpservlet.getOutputStream(); 
    JasperExportManager.exportReportToPdfStream(jasperprint, servletout); 
    FacesContext.getCurrentInstance().responseComplete(); 
} 
Смежные вопросы