I am using grails and I have this Jasper report with a subreport in it.
Having this simple two jasper reports
Note: Only .jrxml is the file extension of the files inside the /web-app/reports
Main Report [main_report][subreport area]
<subreport>
<reportElement x="0" y="0" width="555" height="157"/>
<subreportExpression>
<![CDATA[$P{SUBREPORT_DIR} + "test_report.jasper"]]>
</subreportExpression>
</subreport>
Test report [test_report][title.band]
<staticText>
<reportElement x="203" y="30" width="154" height="34"/>
<textElement/>
<text><![CDATA[Hello World]]></text>
</staticText>
And looking in the view or the gsp file I have this command
<g:jasperReport jasper="main_report"
format="pdf, html"
delimiter=" "/>
When I want to view the report in either PDF of HTML format, the report returns a blank page. Am I missing something to display the main_report properly with a subreport test_report.
You need to:
Make sure the sub-report is compiled (do this in iReport), i.e. there should be a .jasper file for sub report in reports dir.
Set the SUBREPORT_DIR parameter before generating the report, e.g.
params.SUBREPORT_DIR = servletContext.getRealPath('/reports') + "/"
(assuming the compiled subreport is in the <app>/web-app/reports directory, the same as the uncompiled reports).
Related
I'm generating PDF reports using Jasper reports and I have hyperlink in generated file that doesn't work on smartphones when I open it using Adobe Acrobat Reader.
Code to create the hyperlink
<textField hyperlinkType="Reference" hyperlinkTarget="Blank">
<reportElement mode="Opaque" x="450" y="80" width="100" height="20" forecolor="#0080FF" uuid="d11cac12-8769-450c-b9e8-f512179f33e3">
<printWhenExpression><![CDATA[$V{PAGE_NUMBER} == 1]]></printWhenExpression>
</reportElement>
<textElement textAlignment="Left">
<font size="10" isUnderline="true"/>
</textElement>
<textFieldExpression><![CDATA["Go"]]></textFieldExpression>
<hyperlinkReferenceExpression><![CDATA["https://www.google.com"]]></hyperlinkReferenceExpression>
</textField>
In Jaspersoft Studio, set the Link Target to ‘self’, it works for me. The Link Type is ‘Reference’.
How to execute drill down sub report as a pop up in the same window?
Now it is drilling down in the same window of JasperReports Server.
Below is the code :
<textField hyperlinkType="ReportExecution">
<reportElement mode="Opaque" x="0" y="0" width="60" height="20" forecolor="#2471D6" uuid="dcbcfbd0-98a4-4c94-a7a5-01ff9bff8db8"/>
<textElement textAlignment="Center" verticalAlignment="Middle"> <font isUnderline="true"/> </textElement>
<textFieldExpression><![CDATA[$V{resourceunique1}]]></textFieldExpression> <hyperlinkParameter name="_report">
<hyperlinkParameterExpression><![CDATA["jrepo:/ca_ppm/ReportsCustom/subReports/ResourceCapacityGridByProjectReport"]]></hyperlinkParameterExpression>
</textField>
I need pop up in the parameter "_report" can I directly give the javascript inside the "_report" parameters expression. If so, can you please lead me to achieving it
You can open a report in a popup window by filling in the Hyperlink tab in Jaspersoft Studio with these values. Note you need add your server URL:
Link Target: Self
Link Type: Reference
Hyperlink Reference Expression: "javascript:void(window.open("jasperserver-url/flow.html?_flowId=viewReportFlow&reportUnit=/public/Resources/Reports/ca_ppm/ReportsCustom/subReports/ResourceCapacityGridByProjectReport&decorate=no'" +","+"\'\'"+","+"\'height=480,width=950,scrollbars=no,resizable=yes,status=no,toolbar=no,menubar=no,location=no\'"+"));"
I create a Java application to modify some SVG files.
Here is my issue :
I would like to add an elements to the DOM of my SVG files to create link on a rectangle.
The SVG file is generated from another application.
I need to do it in Java.
So here is what I did :
I used JASXP to try to parse and modify my SVG file.
I tried many configurations, using SAX, DOM API to parse it and here is the only which I success to create a document from my SVG file.
Here is my SVGFile :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
<svg ... xmlns:xlink="http://www.w3.org/1999/xlink" ....xmlns="http://www.w3.org/2000/svg" ...>
<!--Generated by the Batik Graphics2D SVG Generator-->
<defs id="genericDefs"/>
<g>
<defs id="defs1">
....define the clipath...
</defs>
HERE I WOULD LIKE TO INSERT OPEN A ELEMENT : <a ....>
<g font-size="11" transform="translate(2,212)" fill-opacity="1"fill="rgb(192,255,255)" text-rendering="geometricPrecision" font-family="sans-serif" stroke="rgb(192,255,255)" font-weight="bold" stroke-opacity="1">
<rect x="0" width="80" height="40" y="0" clip-path="url(#clipPath1)" stroke="none"/>
</g>
<g font-size="11" stroke-linecap="butt" transform="translate(2,212)" fill-opacity="1" fill="black" text-rendering="geometricPrecision" font-family="sans-serif" stroke-linejoin="round" stroke="black" font-weight="bold" stroke-opacity="1" stroke-miterlimit="0">
<rect fill="none" x="0" width="80" height="40" y="0" clip-path="url(#clipPath1)"/>
</g>
<g font-size="11" transform="translate(2,212)" fill-opacity="1" fill="black" text-rendering="geometricPrecision" font-family="sans-serif" stroke="black" font-weight="bold" stroke-opacity="1">
<text x="28" xml:space="preserve" y="12" clip-path="url(#clipPath4)"stroke="none" >Titre</text>
<line y2="12" fill="none" x1="28" clip-path="url(#clipPath4)" x2="52" y1="12"/>
</g>
</g>
</svg>
AND I WOULD LIKE TO CLOSE IT here : </a>
The code to obtain a DOM document from my SVG :
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
File file = new File ("D:/mySVGFile.svg");
String uri = file.toURI().toString();
Document doc = f.createDocument(uri);
To parse the document obtain I did that :
Element racine = doc.getDocumentElement();
String tag ="text"; // Because it's the only element I have store in an Array
NodeList liste = doc.getElementsByTagName(tag);
Element e = (Element) liste.item(0); // element text = Titre
Node target = e.getParentNode().getParentNode().getParentNode();
Element link = doc.createElement("a");
link.setAttribute("xlink:href", "DestinationFile.svg#67");
target.insertBefore(link, target);
Here is the console error :
org.w3c.dom.DOMException: The child node (type: 1, name: svg) is missing.
at org.apache.batik.dom.AbstractNode.createDOMException(AbstractNode.java:408)
at org.apache.batik.dom.AbstractParentNode.insertBefore(AbstractParentNode.java:78)
at SAXTagCount.main(SAXTagCount.java:60)
In fact I really don't know how can I create this element in Java for an SVG files.
Thanks by advance for your help !
Jim
The line
Element link = doc.createElement("a");
is incorrect. To create an SVG <a> element, or indeed any svg element you must use createElementNS i.e.
Element link = doc.createElementNS("http://www.w3.org/2000/svg", "a");
One of your other problems is that you have too many getParentNode() calls. The parent of the text element is its enclosing <g>. Its parent is another <g> and its parent is the <svg> root element so your insertBefore is trying to insert the <a> before the <svg> root element and that's not allowed. Looks to me like you need to remove 2 getParentNode() calls to put it at the right level.
You've various other issues like inserting at the right place - somehow you need to find that <g> element and ideally it would have an id or some way to identify it otherwise you'd have to search for it. Also you'd need to collect all the elements you want to make into children of the <a>. You'd to that by reparenting each existing element using link.appendChild so that its a child of the <a> element. That's a lot to cover in one answer though.
target.insertBefore(link, target);
isn't valid either as you can't use target twice. The argument should be a child of target, not target itself.
/**
* Use the SAXSVGDocumentFactory to parse the given URI into a DOM.
*
* #param uri
* The path to the SVG file to read.
* #return A Document instance that represents the SVG file.
* #throws Exception
* The file could not be read.
*/
private Document createSVGDocument(String uri) throws IOException {
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);
return factory.createDocument(uri);
}
Can this be done? I have tried but parameter is not transmitted. Only the first selected value appear in generated link and then in the report i am opening when clicking hyperlink, I get null value.
Thanks
jrxml hyperlink code:
<textField hyperlinkType="RemotePage" hyperlinkTarget="Blank">
<reportElement uuid="1e57b233-2612-4956-8808-070dc9bcb2f5" x="548" y="30" width="222" height="17"/>
<textElement textAlignment="Right"><font size="12"/> </textElement>
<textFieldExpression><![CDATA["RawData >> Click Here"]]></textFieldExpression>
<hyperlinkTooltipExpression><![CDATA["Click to view RawData"]]></hyperlinkTooltipExpression>
<hyperlinkParameter name="_report">
<hyperlinkParameterExpression><![CDATA["repo:/Team_Reports/CIR_RawData"]]></hyperlinkParameterExpression>
</hyperlinkParameter>
<hyperlinkParameter name="Project_Sets2">
<hyperlinkParameterExpression><![CDATA[$P{Project_Sets}]]></hyperlinkParameterExpression>
</hyperlinkParameter>
</textField>
I want to add hyperlinks to my report. The hyperlink set in one report should take me to another subreport. Could you please tell me if this is feasible. If it is could you please provide step by step approach to achieve this?
First, yes, it is feasible.
Second, here are your step-by-step instructions:
Right click on element you want to link from and select
Hyperlink.
Choose Hyperlink target: Blank
Choose Hyperlink type: Reference
In the reference tab, type the url to invoke the
subreport (with parameters). For example, in one of my reports I
call the ReportController servlet to create the subreport, like so:
"./ReportController?reportName=ValidationDetailsChart&reportTitle=Validation%20Details&nParms=3&parmName_1=ORD_NUMBER&parmValue_1=" + $F{ORDER_NUMBER} + "&parmName_2=START_TIME_MS&parmValue_2=&parmName_3=END_TIME_MS&parmValue_3="
Add a tooltip in the Tooltip tab (optional). Note you can reference variable and paramter values in the tooltip.
Note that there are other ways to do this, and your method may vary if you aren't using java and servlets to generate your reports. I would recommend looking at the ireport documentation for further instructions.
I got the solution to my problem. I had no requirement where I had to to pass any value from one subreport to another. So I simply right clicked on the textfield that I wanted the link on. I set the Hyperlink target as "Self" and Hyperlink type as "LocalPage" and in Hyperlink Page expression I set the following expression : Integer.valueOf(i) ,where i is page number(in my case it was sheet number) where I want the hyperlink to take me. If you want you can also use the following property : Integer.valueOf($V{REPORT_COUNT}).
Thanks everyone for the response.
For navigation within reports I have implemented using Hyperlinks and Anchors
Below is the text field with hyperlinkAnchorExpression, this will be the link.
Note the hyperlinkType="LocalAnchor"
<textField isStretchWithOverflow="true" hyperlinkType="LocalAnchor">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="80" y="0" width="80" height="20" forecolor="#3286C7" uuid="9a8313d2-21f3-4cd2-8e40-f9cddeb3cdaf"/>
<box topPadding="3" leftPadding="3">
<topPen lineWidth="0.2"/>
<leftPen lineWidth="0.2"/>
<bottomPen lineWidth="0.2"/>
<rightPen lineWidth="0.2"/>
</box>
<textElement>
<font isUnderline="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{cAddress}.getId()]]></textFieldExpression>
<hyperlinkAnchorExpression><![CDATA[$F{cAddress}.getId().toString()]]></hyperlinkAnchorExpression>
</textField>
Below is the anchornameexpression, this will be called when a hyperlink is clicked and values is matched with the hyperlinkAnchorExpression value anywhere in the report.
</textField>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="80" y="0" width="80" height="20" uuid="9a8313d2-21f3-4cd2-8e40-f9cddeb3cdaf"/>
<box topPadding="3" leftPadding="3">
<topPen lineWidth="0.2"/>
<leftPen lineWidth="0.2"/>
<bottomPen lineWidth="0.2"/>
<rightPen lineWidth="0.2"/>
</box>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
<anchorNameExpression><![CDATA[$F{id}.toString()]]></anchorNameExpression>
</textField>
I have implemented this to navigate across reports and subreports.
Hope this will be helpful.