I have recently upgraded Jasper Report API from 4.5.1 to 6.3. With 4.5.1, reports are exported to HTML, PDF format. For HTML reports, there is a facility to drill down to child report. In order to customise links to handle request parameters and pre processing of opening child report have created ExtensionRegistryFactory
and registered JRHyperlinkProducerMapFactory
to handle Hyperlinks.
I've noticed that extension is registered properly but it does not getting used. Checked source code of Jasper Report 6.3 and try to debug why, then observed that method: net.sf.jasperreports.engine.JRAbstractExporter.getHyperlinkProducer(JRPrintHyperlink)
does not return JRHyperlinkProducer
.
Here is the code of ExtensionsRegistryFactory
:
public class HyperlinkExtensionsRegistryFactory implements ExtensionsRegistryFactory
{
@Override
public ExtensionsRegistry createRegistry(String registryId, JRPropertiesMap properties)
{
return new ExtensionsRegistry()
{
@Override
public List getExtensions(Class extensionType)
{
if (extensionType.equals(JRHyperlinkProducerFactory.class))
{
JRHyperlinkProducerMapFactory producerFactory = new JRHyperlinkProducerMapFactory();
producerFactory.addProducer("ReportExecution", new RemoteExecutionHyperlinkProducer());
producerFactory.addProducer("Custom", new ExpandCollapseHyperlinkProducer());
return Arrays.asList(producerFactory);
}
return null;
}
};
}
public static class RemoteExecutionHyperlinkProducer implements JRHyperlinkProducer
{
@Override
public String getHyperlink(JRPrintHyperlink hyperlink)
{
return [custom link generation logic];
}
}
public static class ExpandCollapseHyperlinkProducer implements JRHyperlinkProducer
{
@Override
public String getHyperlink(JRPrintHyperlink hyperlink)
{
return [custom link generation logic];
}
}
}
With this class, have created an entry for jasperreports_extension.properties
file. Here is its content:
net.sf.jasperreports.extension.registry.factory.HyperlinkExtensionFactory=<fully_qualified_path_to_HyperlinkExtensionsRegistryFactory>
Am I missing anything? If there is any mistake I am making then kindly help to find out the one.