Jump to content
We've recently updated our Privacy Statement, available here ×

In jaspersoft Studio, how to sum a java.sql.Date


adam22sreginaldo

Recommended Posts

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 by adam22sreginaldo
Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

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;

}

}

image.thumb.png.5e457d22fa0776384a88a78ef5f3750d.png

 

Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...