I found this on the ireport forum (http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=215&func=view&catid=13&id=12642#12642)
"Dynamic subreport
I have a report which shows 200 product codes with their short description. Inside the JasperViewer, the user wants to click on a product code to see product details. The problem is that I do not know in adnavce which product will be clicked. Also, using Hyperlink reference, I can reference only existing reports. Does anybody have an idea, how to do it?
RE: Dynamic subreport
This can be done! I wrote my HyperlinkListener and added it to the JRViewer list of Hyperlink listeners. The subreport layout and datasource name and some parameters must be specified in iReport's Hyperlink Reference Expression using some convetion f.e !subreport.jasper,mySubreportDataSource,param1,param2 .
Inside my HyperlinkReferenceListener class I create the new subreport dynamicly calling JasperFillManager.fillReport(). The JasperPrint object is then shown in separate JasperViewer.
User can drill-down clickink on the hyperlinks.
RE: Dynamic subreport
can u be more elaborate please..?
i want to implement the same situation.
What is this HyperlinkListner class...Is it a user defined class...if so where should write it..
Can u share the code with me..?
any one pls help...how can i drill down by clicking on the hyperlinks and creating dynamic subreports...?
RE: Dynamic subreport
as I informed you by e-mail, I can refer only to
the implementation with the JasperViewer. I have no idea
how to do it with PDF files.
The user click on parent report's hyperlink element is handled in the JRViewer class
which is part of Jasper Reports library. So, create a new class f.e Viewer99
by subclassing JRViewer and add your hyperlink listener, like this
public class Viewer99 extends JRViewer
{
public Viewer99(JasperPrint jrPrint)
{
super(jrPrint);
addHyperlinkListener(new HyperLinkReferenceListener());
}
public Viewer99(InputStream is, boolean isXML) throws JRException
{
super(is, isXML);
}
}
HyperLinkReferenceListener class implements JRHyperlinkListener and could be like this
public class HyperLinkReferenceListener implements JRHyperlinkListener
{
public void gotoHyperlink(JRPrintHyperlink hyperlink)
{
int idx, idx2, i;
DBASource jrData = null;
if (hyperlink.getHyperlinkType() == JRHyperlink.HYPERLINK_TYPE_REFERENCE) {
//System.out.println(hyperlink.getHyperlinkReference());
String hyperlink_reference_exp = hyperlink.getHyperlinkReference();
if (hyperlink_reference_exp.startsWith( ! )){
idx = hyperlink_reference_exp.indexOf(',');
if (idx == -1) return;
//get jasper file name from hyperlink_reference_exp
String jasperReportFile = hyperlink_reference_exp.substring(1,idx);
//get JRDataSource class name
idx2 = hyperlink_reference_exp.indexOf(',', idx+1);
if (idx2 == -1) return;
String dataSourceClass = hyperlink_reference_exp.substring(idx+1,idx2);
//load data source class
try {
//THIS IS FUNDAMENTAL!!! DataSource must be of DBASource type.
//Because parameters can not be passed into the class constructor,
//the DBASource implements setParams mathod.
//Because of the previous there must be a method for connecting
//the database and creating the Resultset - openResultSet method.
//Of course, the OpenResultSet method is called after calling the
//setParams method, because some parametrs can participate in the
//data retrieve SQL statement.
//HyperlinkReference Expression format:
//!report.jasper,MyDataSource,param1,param2,param3,...
//
// where MyDataSource is DBASource subclass
// report.jasper is compiled jasper report layout
// params are Strings passed into Data Source where they
// are addressed by PARAM1,PARAM2,... names
//
jrData = (DBASource) Class.forName(dataSourceClass).newInstance();
}catch (ClassNotFoundException e)
{
e.printStackTrace();
}catch (InstantiationException e1)
{
e1.printStackTrace();
}catch (IllegalAccessException e2)
{
e2.printStackTrace();
}
if (jrData == null) return;
//get parameters
i = 0;
HashMap hm = new HashMap();
while ((idx = hyperlink_reference_exp.indexOf(',', idx2+1)) != -1)
{
hm.put( PARAM + (++i), hyperlink_reference_exp.substring(idx2+1,idx));
idx2 = idx;
}
//get the last parameter
hm.put( PARAM + (++i), hyperlink_reference_exp.substring(idx2+1));
Now the Viewer99 has the ability to catch the user's click on a hyperlink
and invoke the related subreport. Viewer99 must be called inside the JasperViewer.
But instead of modifying the original JasperViewer, craete a new class
JasperViewerE base on it and replace any occurrence of JRViewer by Viewer99 and use
JasperViewerE everywhere you need this feature.
In this implementation, the subreport data source is always class implementing
JRDataSource. You could find some other solution suitable for your needs.
I hope this can help you."
So can implement Adempiere to have feature "Drill-down with Jasper report"???
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I found this on the ireport forum (http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=215&func=view&catid=13&id=12642#12642)
"Dynamic subreport
I have a report which shows 200 product codes with their short description. Inside the JasperViewer, the user wants to click on a product code to see product details. The problem is that I do not know in adnavce which product will be clicked. Also, using Hyperlink reference, I can reference only existing reports. Does anybody have an idea, how to do it?
RE: Dynamic subreport
This can be done! I wrote my HyperlinkListener and added it to the JRViewer list of Hyperlink listeners. The subreport layout and datasource name and some parameters must be specified in iReport's Hyperlink Reference Expression using some convetion f.e !subreport.jasper,mySubreportDataSource,param1,param2 .
Inside my HyperlinkReferenceListener class I create the new subreport dynamicly calling JasperFillManager.fillReport(). The JasperPrint object is then shown in separate JasperViewer.
User can drill-down clickink on the hyperlinks.
RE: Dynamic subreport
can u be more elaborate please..?
i want to implement the same situation.
What is this HyperlinkListner class...Is it a user defined class...if so where should write it..
Can u share the code with me..?
any one pls help...how can i drill down by clicking on the hyperlinks and creating dynamic subreports...?
RE: Dynamic subreport
as I informed you by e-mail, I can refer only to
the implementation with the JasperViewer. I have no idea
how to do it with PDF files.
The user click on parent report's hyperlink element is handled in the JRViewer class
which is part of Jasper Reports library. So, create a new class f.e Viewer99
by subclassing JRViewer and add your hyperlink listener, like this
public class Viewer99 extends JRViewer
{
public Viewer99(JasperPrint jrPrint)
{
super(jrPrint);
addHyperlinkListener(new HyperLinkReferenceListener());
}
public Viewer99(String fileName, boolean isXML) throws JRException
{
super(fileName, isXML);
}
public Viewer99(InputStream is, boolean isXML) throws JRException
{
super(is, isXML);
}
}
HyperLinkReferenceListener class implements JRHyperlinkListener and could be like this
public class HyperLinkReferenceListener implements JRHyperlinkListener
{
public void gotoHyperlink(JRPrintHyperlink hyperlink)
{
int idx, idx2, i;
DBASource jrData = null;
if (hyperlink.getHyperlinkType() == JRHyperlink.HYPERLINK_TYPE_REFERENCE) {
//System.out.println(hyperlink.getHyperlinkReference());
String hyperlink_reference_exp = hyperlink.getHyperlinkReference();
if (hyperlink_reference_exp.startsWith( ! )){
idx = hyperlink_reference_exp.indexOf(',');
if (idx == -1) return;
//get jasper file name from hyperlink_reference_exp
String jasperReportFile = hyperlink_reference_exp.substring(1,idx);
//get JRDataSource class name
idx2 = hyperlink_reference_exp.indexOf(',', idx+1);
if (idx2 == -1) return;
String dataSourceClass = hyperlink_reference_exp.substring(idx+1,idx2);
//load data source class
try {
//THIS IS FUNDAMENTAL!!! DataSource must be of DBASource type.
//Because parameters can not be passed into the class constructor,
//the DBASource implements setParams mathod.
//Because of the previous there must be a method for connecting
//the database and creating the Resultset - openResultSet method.
//Of course, the OpenResultSet method is called after calling the
//setParams method, because some parametrs can participate in the
//data retrieve SQL statement.
//HyperlinkReference Expression format:
//!report.jasper,MyDataSource,param1,param2,param3,...
//
// where MyDataSource is DBASource subclass
// report.jasper is compiled jasper report layout
// params are Strings passed into Data Source where they
// are addressed by PARAM1,PARAM2,... names
//
jrData = (DBASource) Class.forName(dataSourceClass).newInstance();
}catch (ClassNotFoundException e)
{
e.printStackTrace();
}catch (InstantiationException e1)
{
e1.printStackTrace();
}catch (IllegalAccessException e2)
{
e2.printStackTrace();
}
if (jrData == null) return;
//get parameters
i = 0;
HashMap hm = new HashMap();
while ((idx = hyperlink_reference_exp.indexOf(',', idx2+1)) != -1)
{
hm.put( PARAM + (++i), hyperlink_reference_exp.substring(idx2+1,idx));
idx2 = idx;
}
//get the last parameter
hm.put( PARAM + (++i), hyperlink_reference_exp.substring(idx2+1));
//hm.put( PARAM1 , 980-0101-2001 );
//hm.put( PARAM2 , 0527001 );
jrData.setParams(hm);
jrData.openResultSet();
try{
JasperPrint jrPrint = JasperFillManager.fillReport(jasperReportFile,
null,
jrData);
jrData.closeAll();
jrData = null;
JasperViewerE cl = new JasperViewerE(jrPrint);
cl.setVisible(true);
}catch(JRException e)
{
e.printStackTrace();
}
}//if
}//if
}//public void gotoHyperlink
Now the Viewer99 has the ability to catch the user's click on a hyperlink
and invoke the related subreport. Viewer99 must be called inside the JasperViewer.
But instead of modifying the original JasperViewer, craete a new class
JasperViewerE base on it and replace any occurrence of JRViewer by Viewer99 and use
JasperViewerE everywhere you need this feature.
In this implementation, the subreport data source is always class implementing
JRDataSource. You could find some other solution suitable for your needs.
I hope this can help you."
So can implement Adempiere to have feature "Drill-down with Jasper report"???
Hi,
>So can implement Adempiere to have feature "Drill-down with Jasper report"???
Sure.
You can do it
or
you can support someone else to do it
or
someone else can do it
or
someone else can support other developer to do it.
Kind regards,
Trifon