adam22sreginaldo Posted December 18, 2023 Share Posted December 18, 2023 (edited) Hello, I'm making a report that needs a subTotal in every page that gives the total of hours until that page. The field that im using is a java.util.Date. !!!The problem is that the variable that sum always give me the last Time of that page. I'm using a variable that I put in the page footer that have: - name: SumHours - Value Class Name: java.util.date - Calculation: Sum - Expression: $F{Time} - Increment Type: Page - Reset Type: None Edited December 18, 2023 by adam22sreginaldo Link to comment Share on other sites More sharing options...
Thomas Tibcken Posted December 18, 2023 Share Posted December 18, 2023 Hi, can you please share an example based on the sample db that will show your challange in more details? THX TT Link to comment Share on other sites More sharing options...
adam22sreginaldo Posted December 19, 2023 Author Share Posted December 19, 2023 23 hours ago, adam22sreginaldo said: Hello, I'm making a report that needs a subTotal in every page that gives the total of hours until that page. The field that im using is a java.util.Date. !!!The problem is that the variable that sum always give me the last Time of that page. I'm using a variable that I put in the page footer that have: - name: SumHours - Value Class Name: java.util.date - Calculation: Sum - Expression: $F{Time} - Increment Type: Page - Reset Type: None .zul: <?page title="_new page title" contentType="text/html;charset=UTF-8"?> <zk> <window id="titulo" title="_LanzarReporte" border="normal" apply="main.Main" height="800px" width="800px"> <panel> <panelchildren> <button id="visualizarPDF" width="24%" label="_Visualizar PDF en esta pagina" Tooltiptext = "_Visualizar PDF en esta pagina" > </button> </panelchildren> </panel> <iframe id="iframe" vflex="1" hflex="1"></iframe> </window> </zk> Main.java public class Main extends GenericForwardComposer{ private static ReportModel dataSource; private static HashMap hm = new HashMap<>(); private static List<Data> datosList = new ArrayList<>(); Iframe iframe; public void onClick$visualizarPDF() throws JRException, FileNotFoundException { InputStream reportStream = new FileInputStream(new File("C:\\Users\\sro\\JaspersoftWorkspace\\MyReports\\ReportTimeTest.jasper")); for (int i = 0; i < 600; i++) { datosList.add(new Data(new java.util.Date(0, 0, 0, 1, 23))); datosList.add(new Data(new java.util.Date(0, 0, 0, 4, 40))); datosList.add(new Data(new java.util.Date(0, 0, 0, 5, 15))); } dataSource = new ReportModel(datosList); hm.put("pColumn1Name", "Time"); byte[] buf = JasperRunManager.runReportToPdf(reportStream, hm, dataSource); InputStream mediais = new ByteArrayInputStream(buf); AMedia amedia = new AMedia("InformePDFVisual.pdf", "pdf", "application/pdf", mediais); iframe.setContent(amedia); } } Data.java public class Data { private Date fHours; public Data(Date Hours) { super(); this.fHours = Hours; } public Date getfHours() { return fHours; } public void setfHours(Date fHours) { this.fHours = fHours; } } ReportModel.java public class ReportModel implements JRDataSource{ //Variables private List<Data> dataList; private int indiceActual = -1; public ReportModel(List<Data> dataList) { this.dataList = dataList; } @Override public boolean next() throws JRException { indiceActual++; return indiceActual < dataList.size(); } @Override public Object getFieldValue(JRField jrField) throws JRException { if ("fHours".equals(jrField.getName())) { return (indiceActual < dataList.size()) ? dataList.get(indiceActual).getfHours() : null; } return null; } } Link to comment Share on other sites More sharing options...
Thomas Tibcken Posted December 19, 2023 Share Posted December 19, 2023 On 12/18/2023 at 9:38 AM, adam22sreginaldo said: Hello, I'm making a report that needs a subTotal in every page that gives the total of hours until that page. The field that im using is a java.util.Date. !!!The problem is that the variable that sum always give me the last Time of that page. I'm using a variable that I put in the page footer that have: - name: SumHours - Value Class Name: java.util.date - Calculation: Sum - Expression: $F{Time} - Increment Type: Page - Reset Type: None Hi, can you please upload the full .jrxm file and not just copy & past code. The Editor will not keep it as it should be. THX TT Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now