gpt4 book ai didi

java - 在 focframework 中,我如何制作一个按钮来打印多个 Jasper 报告,这些报告在一次打印中连接在一起

转载 作者:行者123 更新时间:2023-11-30 07:44:17 24 4
gpt4 key购买 nike

我正在使用 focframework构建我的网络应用程序。我已经在 focframework 中独立开发并正常工作了一些独立的 Jasper 报告。现在我想要一个按钮,通过将它们连接在同一个 PDF 文件中,可以一次打印它们。

显然我会使用 Vaadin BrowserWindowOpener 如下。但是我应该准备一个资源对象。

StreamResource resource = ???;
BrowserWindowOpener browserWindowOpener = new BrowserWindowOpener(resource);
browserWindowOpener.extend(button);

知道如何将 Jasper 报告的串联放置在 StreamResource 对象中吗?

我知道有一些答案可以解释一般如何做,但因为我使用的是 focframework我想要一个更有针对性的答案,允许我使用现有的焦点开发(如果有的话)。

最佳答案

正如您在问题中提到的,使用 BrowserWindowOpener 看起来是正确的方法。

StreamResource resource = ???;
BrowserWindowOpener browserWindowOpener = new BrowserWindowOpener(resource);
browserWindowOpener.extend(button);

要获取“StreamResource 资源”,我们可以执行以下操作:

StreamResource resource = new StreamResource(streamSource, "printnig_"+System.currentTimeMillis()+".pdf");
resource.setMIMEType("application/pdf");

现在我们需要一个 com.vaadin.server.StreamSource 类型的 streamSource。为此,我们有一个连接报告的专用类,我希望这能满足您的需求:

FStreamSource_Report<MyUserDataClass> streamSource = new FStreamSource_Report<MyUserDataClass>(myUserDataClassInstance) {
protected void init(int reportIndex){
//init to print the report at reportIndex.
}

protected void shut(int reportIndex){
//dispose the necessary data for reportIndex
}

protected boolean next(int reportIndex){
//Return true if you have a report to print at reportIndex
}

protected String getReportFileName(int reportIndex){
//Return the report filename at reportIndex
}

protected JRFocObjectParameters getParams(int reportIndex){
//Return the JRFocObjectParameters needed for reportIndex
}

protected JRFocListDataSource getDataSource(int reportIndex){
//Return the Jasper/foc Data source for the Jasper details section at reportIndex
}

您显然必须实现上面列出的不同方法。这些方法调用将告诉 FStreamSource_Report 它有多少底层报表,并且每次都会调用它们来为这些报表准备数据。

MyUserDataClass:是您选择的一个类,您可以使用 getUserData() 在不同的方法实现中访问它;

这是一个例子: FStreamSource_Report streamSource = new FStreamSource_Report(prodProgram) {

    private PrintingAction printingAction = null;

@Override
protected void init(int reportIndex) {
if(reportIndex == 0){//Raw Material printout
ProductionProgram productionProgram = getUserData();
printingAction = RawMaterialReportDesc.getInstance().newPrintingAction();
printingAction.setObjectToPrint(productionProgram);
printingAction.initLauncher();

}else if(reportIndex == 1){//Production Steps
ProductionProgram productionProgram = getUserData();
printingAction = ProductionStepsReportDesc.getInstance().newPrintingAction();
printingAction.setObjectToPrint(productionProgram);
printingAction.initLauncher();

}else if(reportIndex == 2){//Production Steps
ProductionProgram productionProgram = getUserData();
printingAction = FinishedProductsReportDesc.getInstance().newPrintingAction();
printingAction.setObjectToPrint(productionProgram);
printingAction.initLauncher();
}
}

@Override
protected void shut(int reportIndex) {
if(printingAction != null){
printingAction.dispose();
}
}

@Override
protected String getReportFileName(int reportIndex) {
String fileName = null;
PrnContext prnContext = ReportFactory.getInstance().findContext("PRODUCTION_CONTEXT");
if (prnContext != null) {
PrnLayout prnLayout = null;
if(reportIndex == 0) {
prnLayout = prnContext.getLayoutByName("RAW_MATERIAL");
}else if(reportIndex == 1) {
prnLayout = prnContext.getLayoutByName("STEPS");
}else if(reportIndex == 2) {
prnLayout = prnContext.getLayoutByName("FINISHED_PRODUCTS");
}
if (prnLayout != null) {
fileName = printingAction != null ?
printingAction.getLauncher().getReportFileName(prnLayout) : null;
}
}
return fileName;
}

@Override
protected JRFocObjectParameters getParams(int reportIndex) {
JRFocObjectParameters params = null;
if(reportIndex == 0 || reportIndex == 1 || reportIndex == 2){
//I am using the same header FocObject for all 3 reports
ProductionProgram productionProgram = getUserData();
params = new JRFocObjectParameters(productionProgram);
}
}

@Override
protected JRFocListDataSource getDataSource(int reportIndex) {
JRFocListDataSource source = null;
if(reportIndex == 0){//Raw material
ProductionProgram productionProgram = getUserData();
source = new JRFocListDataSource(productionProgram.getRawMaterialFocList());
}else if(reportIndex == 1){//Production Steps
ProductionProgram productionProgram = getUserData();
source = new JRFocListDataSource(productionProgram.getProductionStepsFocList());
}else if(reportIndex == 2){//Production Steps
ProductionProgram productionProgram = getUserData();
source = new JRFocListDataSource(productionProgram.getFinishedGoodsFocList());
}

return source;
}

@Override
protected boolean next(int reportIndex) {
return reportIndex <= 2;//Because we have 3 printouts 1,2,3
}
};

关于java - 在 focframework 中,我如何制作一个按钮来打印多个 Jasper 报告,这些报告在一次打印中连接在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52718622/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com