如果之前已经回答过,请原谅我,但我无法在任何地方找到有关它的更多信息。
我在Domino中编写了一些Java,将字段值传递给Jasper报告并生成PDF结果。该报告还包含子报告和子报告。因此,基本上,我得到主报表的字段值列表,其中一个是子报表的字段值数组。在子报表数组的每个记录中,可能存在子报表的另一个字段值数组。很简单。
我的所有Domino数据检索都在一个bean中完成,我在那里初始化了NotesContext,所以我很困惑为什么我仍然会收到这个错误。
就像背景一样......我上周开始学习如何做到这一点,并且能够成功地将硬编码数据传递给PDF。这是我第一次尝试从Domino数据库传递值。
这是获取Domino数据的DataBeanList类:
import java.util.*;
import lotus.domino.*;
import com.ibm.domino.xsp.module.nsf.NotesContext;
import com.hsdomino.jasper.SubReportBeanWS;
import com.hsdomino.jasper.SubReportBeanMisc;
public class DataBeanList {
//this class populates an object array of all the field value objects for the report
//for subreports, there will be multiple objects in the subreport beans, one for each detail band
public ArrayList<DataBean> getDataBeanList(String docnum) {
//create the array to return
ArrayList<DataBean> dataBeanList = new ArrayList<DataBean>();
//this will be a single record array consisting of a series of fields and array of ws subreport
//fields that contains another array of misc subsubreport fields
try{
NotesContext ctx = NotesContext.getCurrent();
Session sess = ctx.getCurrentSession();
Database db = sess.getCurrentDatabase();
View baseview = db.getView("QuoteLetterBase_Java");
View wsview = db.getView("QuoteLetterWS");
View miscview = db.getView("QuoteLetterMisc");
//get the base data
ViewEntry ventry = baseview.getEntryByKey(docnum,true);
String repquote = ventry.getColumnValues().get(1).toString();
String custname = ventry.getColumnValues().get(2).toString();
String custnum = ventry.getColumnValues().get(3).toString();
String custadd_2 = ventry.getColumnValues().get(4).toString();
String custadd_3 = ventry.getColumnValues().get(5).toString();
String custadd_4 = ventry.getColumnValues().get(6).toString();
String custadd_5 = ventry.getColumnValues().get(7).toString();
String custadd_6 = ventry.getColumnValues().get(8).toString();
String contact = ventry.getColumnValues().get(9).toString();
String contactemail = ventry.getColumnValues().get(10).toString();
String contactphone = ventry.getColumnValues().get(11).toString();
String program = ventry.getColumnValues().get(12).toString();
String inqnum = ventry.getColumnValues().get(13).toString();
String fob = ventry.getColumnValues().get(14).toString();
String terms = ventry.getColumnValues().get(15).toString();
String estimator = ventry.getColumnValues().get(16).toString();
String saleseng = ventry.getColumnValues().get(17).toString();
String expires = ventry.getColumnValues().get(18).toString();
String qnotes = ventry.getColumnValues().get(19).toString();
String bottomterms = ventry.getColumnValues().get(20).toString();
String tmp = ventry.getColumnValues().get(21).toString();
Double totalquote = Double.parseDouble(tmp);
String docnumoption = ventry.getColumnValues().get(22).toString();
String datesentoption = ventry.getColumnValues().get(23).toString();
String id = ventry.getColumnValues().get(24).toString();
String draft = ventry.getColumnValues().get(25).toString();
String contactscc = ventry.getColumnValues().get(26).toString();
//get the wsdata as an array
ViewEntryCollection vecol = wsview.getAllEntriesByKey(docnum,true);
ArrayList<SubReportBeanWS> wssubRepList = new ArrayList<SubReportBeanWS>();
if(vecol.getCount()>0){
ViewEntry wsventry = vecol.getFirstEntry();
while(wsventry!=null){
String line = wsventry.getColumnValues().get(2).toString();
String group1 = wsventry.getColumnValues().get(3).toString();
String group2 = wsventry.getColumnValues().get(4).toString();
String group3 = wsventry.getColumnValues().get(5).toString();
String group4 = wsventry.getColumnValues().get(6).toString();
String qnotes1 = wsventry.getColumnValues().get(8).toString();
String qnotes2 = wsventry.getColumnValues().get(9).toString();
String qnotes3 = wsventry.getColumnValues().get(10).toString();
String qnotes4 = wsventry.getColumnValues().get(11).toString();
String qnotes5 = wsventry.getColumnValues().get(12).toString();
String qnotes6 = wsventry.getColumnValues().get(13).toString();
String qnotes7 = wsventry.getColumnValues().get(14).toString();
String qnotes8 = wsventry.getColumnValues().get(15).toString();
String qnotes9 = wsventry.getColumnValues().get(16).toString();
String qnotes10 = wsventry.getColumnValues().get(17).toString();
String tmpws = wsventry.getColumnValues().get(18).toString();
Double totalquotews = Double.parseDouble(tmpws);
String wsdocnum = wsventry.getColumnValues().get(19).toString();
//get the misc data list as an array
ArrayList<SubReportBeanMisc> miscsubRepList = new ArrayList<SubReportBeanMisc>();
ViewEntryCollection miscvecol = miscview.getAllEntriesByKey(wsdocnum,true);
if(miscvecol.getCount()>0){
ViewEntry miscventry = miscvecol.getFirstEntry();
while(miscventry!=null){
String miscgroup1 = miscventry.getColumnValues().get(3).toString();
String tmpmisc = miscventry.getColumnValues().get(9).toString();
Double totalquotemisc = Double.parseDouble(tmpmisc);
//create a misc bean to store in the misc array
SubReportBeanMisc miscsubbean = new SubReportBeanMisc();
miscsubbean.setGroup1(miscgroup1);
miscsubbean.setTotalquote(totalquotemisc);
miscsubRepList.add(miscsubbean);
ViewEntry tmpmiscve = miscvecol.getNextEntry(miscventry);
miscventry.recycle();
miscventry = tmpmiscve;
}
}
miscvecol.recycle();
//create a ws bean to store in the base array
SubReportBeanWS wssubbean = new SubReportBeanWS();
wssubbean.setLine(line);
wssubbean.setGroup1(group1);
wssubbean.setGroup2(group2);
wssubbean.setGroup3(group3);
wssubbean.setGroup4(group4);
wssubbean.setQnotes1(qnotes1);
wssubbean.setQnotes2(qnotes2);
wssubbean.setQnotes3(qnotes3);
wssubbean.setQnotes4(qnotes4);
wssubbean.setQnotes5(qnotes5);
wssubbean.setQnotes6(qnotes6);
wssubbean.setQnotes7(qnotes7);
wssubbean.setQnotes8(qnotes8);
wssubbean.setQnotes9(qnotes9);
wssubbean.setQnotes10(qnotes10);
wssubbean.setTotalquote(totalquotews);
wssubbean.setWsdocnum(wsdocnum);
wssubbean.setSubReportBeanMiscList(miscsubRepList);
wssubRepList.add(wssubbean);
ViewEntry tmpve = vecol.getNextEntry(wsventry);
wsventry.recycle();
wsventry = tmpve;
}
vecol.recycle();
}
//create the base quote bean array
dataBeanList.add(produce(docnum,repquote,custname,custnum,custadd_2,custadd_3,custadd_4,custadd_5,custadd_6,contact,contactemail,contactphone,
program,inqnum,fob,terms,estimator,saleseng,expires,qnotes,bottomterms,totalquote,docnumoption,datesentoption,id,draft,contactscc,wssubRepList));
ventry.recycle();
baseview.recycle();
wsview.recycle();
miscview.recycle();
}
catch(NotesException e){
System.out.println("Error in DataBeanList: " + e);
}
return dataBeanList;
}
/**
* This method returns a DataBean object,
* with all the fields for the main report in it (and an array for the WS subreport
* which contains an array for th misc subreport)
*/
private DataBean produce(String qnum, String repquote, String custname, String custnum, String custadd_2,
String custadd_3, String custadd_4, String custadd_5, String custadd_6, String contact, String contactemail,
String contactphone, String program, String inqnum, String fob, String terms, String estimator, String saleseng,
String expires, String qnotes, String bottomterms, Double totalquote, String docnumoption, String datesentoption,
String id, String draft, String contactscc, List<SubReportBeanWS> subBean) {
DataBean dataBean = new DataBean();
dataBean.setDocnum(qnum);
dataBean.setRepquote(repquote);
dataBean.setCustname(custname);
dataBean.setCustnum(custnum);
dataBean.setCustadd_2(custadd_2);
dataBean.setCustadd_3(custadd_3);
dataBean.setCustadd_4(custadd_4);
dataBean.setCustadd_5(custadd_5);
dataBean.setCustadd_6(custadd_6);
dataBean.setContact(contact);
dataBean.setContactemail(contactemail);
dataBean.setContactphone(contactphone);
dataBean.setProgram(program);
dataBean.setInqnum(inqnum);
dataBean.setFob(fob);
dataBean.setTerms(terms);
dataBean.setEstimator(estimator);
dataBean.setSaleseng(saleseng);
dataBean.setExpires(expires);
dataBean.setQnotes(qnotes);
dataBean.setBottomterms(bottomterms);
dataBean.setTotalquote(totalquote);
dataBean.setDocnumoption(docnumoption);
dataBean.setDatesentoption(datesentoption);
dataBean.setId(id);
dataBean.setDraft(draft);
dataBean.setContactscc(contactscc);
dataBean.setSubReportBeanWSList(subBean);
return dataBean;
}
}
而且,这里是错误堆栈:
javax.faces.FacesException: Error while executing JavaScript action expression
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:102)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:96)
at com.ibm.xsp.controller.FacesControllerImpl.execute(FacesControllerImpl.java:256)
at com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:227)
at com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:157)
at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:159)
at com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)
at com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:588)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1335)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:865)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:808)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:577)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1319)
at com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:662)
at com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:482)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:357)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:313)
at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)
Caused by: com.ibm.xsp.exception.EvaluationExceptionEx: Error while executing JavaScript action expression
at com.ibm.xsp.binding.javascript.JavaScriptMethodBinding.invoke(JavaScriptMethodBinding.java:126)
at com.ibm.xsp.actions.ExecuteScriptAction.invoke(ExecuteScriptAction.java:78)
at com.ibm.xsp.application.ActionListenerImpl.processAction(ActionListenerImpl.java:60)
at javax.faces.component.UICommand.broadcast(UICommand.java:324)
at com.ibm.xsp.component.UIEventHandler.broadcast(UIEventHandler.java:366)
at com.ibm.xsp.component.UIDataPanelBase.broadcast(UIDataPanelBase.java:400)
at com.ibm.xsp.component.UIDataIterator.broadcast(UIDataIterator.java:694)
at com.ibm.xsp.component.UIDataPanelBase.broadcast(UIDataPanelBase.java:400)
at com.ibm.xsp.component.UIDataPanelBase.broadcast(UIDataPanelBase.java:400)
at com.ibm.xsp.component.UIDataPanelBase.broadcast(UIDataPanelBase.java:400)
at com.ibm.xsp.component.UIDataPanelBase.broadcast(UIDataPanelBase.java:400)
at com.ibm.xsp.component.UIDataPanelBase.broadcast(UIDataPanelBase.java:400)
at com.ibm.xsp.component.UIDataPanelBase.broadcast(UIDataPanelBase.java:400)
at com.ibm.xsp.component.UIViewRootEx.broadcast(UIViewRootEx.java:1535)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:307)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:428)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:94)
... 19 more
Caused by: com.ibm.jscript.InterpretException: Script interpreter error, line=4, col=5: Error calling method 'reportToFile(string)' on java class 'com.hsdomino.jasper.CreatePDF'
at com.ibm.jscript.types.JavaAccessObject.call(JavaAccessObject.java:335)
at com.ibm.jscript.types.FBSObject.call(FBSObject.java:161)
at com.ibm.jscript.ASTTree.ASTCall.interpret(ASTCall.java:197)
at com.ibm.jscript.ASTTree.ASTProgram.interpret(ASTProgram.java:119)
at com.ibm.jscript.ASTTree.ASTProgram.interpretEx(ASTProgram.java:139)
at com.ibm.jscript.JSExpression._interpretExpression(JSExpression.java:435)
at com.ibm.jscript.JSExpression.access$1(JSExpression.java:424)
at com.ibm.jscript.JSExpression$2.run(JSExpression.java:414)
at java.security.AccessController.doPrivileged(AccessController.java:686)
at com.ibm.jscript.JSExpression.interpretExpression(JSExpression.java:410)
at com.ibm.jscript.JSExpression.evaluateValue(JSExpression.java:251)
at com.ibm.jscript.JSExpression.evaluateValue(JSExpression.java:234)
at com.ibm.xsp.javascript.JavaScriptInterpreter.interpret(JavaScriptInterpreter.java:222)
at com.ibm.xsp.binding.javascript.JavaScriptMethodBinding.invoke(JavaScriptMethodBinding.java:111)
... 35 more
Caused by: java.lang.RuntimeException: error in CreatePDF:
at com.hsdomino.jasper.CreatePDF.reportToFile(CreatePDF.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:508)
at com.ibm.jscript.types.JavaAccessObject.call(JavaAccessObject.java:322)
... 48 more
Caused by: net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: new java.lang.Integer(1)
at net.sf.jasperreports.engine.fill.JRFillSubreport.prepare(JRFillSubreport.java:874)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:536)
at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:411)
at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:386)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2024)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:748)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:255)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:115)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:580)
at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:414)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:121)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:583)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:929)
at com.hsdomino.jasper.CreatePDF.reportToFile(CreatePDF.java:53)
... 53 more
Caused by: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: new java.lang.Integer(1)
at net.sf.jasperreports.engine.fill.JREvaluator.evaluateEstimated(JREvaluator.java:352)
at net.sf.jasperreports.engine.fill.JRCalculator.evaluateEstimated(JRCalculator.java:607)
at net.sf.jasperreports.engine.fill.JRCalculator.estimateVariables(JRCalculator.java:208)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1276)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1250)
at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1056)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:113)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:580)
at net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:414)
at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:736)
at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:59)
at net.sf.jasperreports.engine.fill.AbstractThreadSubreportRunner.run(AbstractThreadSubreportRunner.java:221)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1153)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.lang.Thread.run(Thread.java:785)
Caused by: java.lang.IllegalStateException: NotesContext not initialized for the thread
at com.ibm.domino.xsp.module.nsf.NotesContext.getCurrent(NotesContext.java:123)
at com.ibm.domino.xsp.module.nsf.ModuleClassLoader$DynamicClassLoader.loadClass(ModuleClassLoader.java:416)
at java.lang.ClassLoader.loadClass(ClassLoader.java:809)
at com.ibm.domino.xsp.module.nsf.ModuleClassLoader.loadClass(ModuleClassLoader.java:209)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:842)
at java.lang.ClassLoader.loadClass(ClassLoader.java:829)
at java.lang.ClassLoader.loadClass(ClassLoader.java:809)
at HSD_QuoteWS_Java_1492633388584_6145.evaluateEstimated(HSD_QuoteWS_Java_1492633388584_6145:599)
at net.sf.jasperreports.engine.fill.JREvaluator.evaluateEstimated(JREvaluator.java:338)
... 14 more
主类运行一切正常以获取数据,但随后在此行产生错误:
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,parameters,beanColDataSource);
我通过在Domino控制台上跟踪它来了解这一点:
[17E0:000D-1F9C] 04/20/2017 02:49:51 PM HTTP JVM: setting reportname
[17E0:000D-1F9C] 04/20/2017 02:49:51 PM HTTP JVM: setting parameters
[17E0:000D-1F9C] 04/20/2017 02:49:51 PM HTTP JVM: setting beancol datasrc
[17E0:000D-1F9C] 04/20/2017 02:49:51 PM HTTP JVM: setting base data
[17E0:000D-1F9C] 04/20/2017 02:49:52 PM HTTP JVM: setting wsdata for line 1.
[17E0:000D-1F9C] 04/20/2017 02:49:52 PM HTTP JVM: - - - checking misc data
[17E0:000D-1F9C] 04/20/2017 02:49:52 PM HTTP JVM: getting misc data for line 1.
[17E0:000D-1F9C] 04/20/2017 02:49:52 PM HTTP JVM: setting subreportbeanws
[17E0:000D-1F9C] 04/20/2017 02:49:52 PM HTTP JVM: setting databeanlist
[17E0:000D-1F9C] 04/20/2017 02:49:52 PM HTTP JVM: calling jasperfillmgr
[17E0:0163-2300] 04/20/2017 02:49:52 PM HTTP JVM: java.lang.IllegalStateException: NotesContext not initialized for the thread. For more detailed information, please consult error-log-0.xml located in C:/Program Files/IBM/XWork/data/domino/workspace/logs
主要班级:
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
public class CreatePDF implements Serializable {
private static final long serialVersionUID = 1L;
public CreatePDF(){
//for managed bean
}
public void reportToFile(String docnum) {
try {
System.out.println("setting reportname");
String jasperReport = "C://Users/RPo/Documents/BobC/Jasper Reports/Studio Reports/MyReports/HSD_Quote_Java.jasper";
String subReportWS = "C://Users/RPo/Documents/BobC/Jasper Reports/Studio Reports/MyReports/HSD_QuoteWS_Java.jasper";
String subReportMisc = "C://Users/RPo/Documents/BobC/Jasper Reports/Studio Reports/MyReports/HSD_QuoteMisc_Java.jasper";
String destReport = "C:/JReports/HSD/"+docnum+".pdf";
System.out.println("setting parameters");
// Parameters for report
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("SubReportWS", subReportWS);
parameters.put("SubReportMisc", subReportMisc);
// DataSource
System.out.println("setting beancol datasrc");
DataBeanList DataBeanList = new DataBeanList();
ArrayList<DataBean> dataList = DataBeanList.getDataBeanList(docnum);
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(dataList);
System.out.println("calling jasperfillmgr");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,parameters,beanColDataSource);
System.out.println("calling exporttopdf");
// Export to PDF.
JasperExportManager.exportReportToPdfFile(jasperPrint,destReport);
System.out.println("Done!");
} catch (Exception e) {
System.out.println("Error in CreatePDF: " + e);
throw new RuntimeException("error in CreatePDF: ", e);
}
}
}
我从ssjs调用这样的代码:
var docnum = rdata.getColumnValue("_DocNum");
var pdf = new com.hsdomino.jasper.CreatePDF;
pdf.reportToFile(docnum)
这个jrxml数据不适合这篇文章(grrrr)。
有人能指出我正确的方向来解决这个问题吗?
更新25APR17,我删除了子报表,它工作得很好!所以,把我的注意力缩小到那个。
答案 0 :(得分:0)
尝试从XPages(JSF)引擎获取会话,如下所示:
Session session = DominoUtils.getCurrentSession();