I want to hide a text field using jasper report so when i will view it in html i wont see its content, but the problem is that it has to be there (proggram JAWS has to read it) so i can't use "printWhenExpression". I tried to use width properties to hide it but so far i have no effect.
<textField>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
If I understood correctly, you need to keep the shape of the box as if the content was here, but you want the content to disappear.
It's true that printWhenExpression will make the whole item disappear.
You can either :
Use a parent item such as a frame to be around the textField, so printWhenExpression is true on the text fields, then the frame will still be here to keep its place.
<frame>
<reportElement x="0" y="0" width="200" height="200" uuid="25b397bf-e718-43ab-8641-4f7c7932253f"/>
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="4e8ea258-88f0-4220-a350-448da63390d1">
<printWhenExpression><![CDATA[the_condition]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
</frame>
Use a java condition in your text field. If the condition is false, the text will disappear but the text field frame will still be displayed.
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="4e8ea258-88f0-4220-a350-448da63390d1">
<printWhenExpression><![CDATA[the_condition]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[my_condition ? $V{PAGE_NUMBER} : ""]]></textFieldExpression>
</textField>
Related
I have a problem with correctly setting paddings in JasperReports tables.
I'm using styles to uniformly configure text boxes of the same purpose, eg. for displaying currency. However, the paddings behave differently in text fields in table body and table footer. Inside the table, the top and bottom padding works correcly, however, left and right not. The 2 pixels are ignored, so I'd have to use 4 to get 2.
In table footer, paddings work normally, which makes numbers misaligned. But the whole footer cell looks to be shifted.
This is my JRXML fragment:
<jr:tableFooter style="Table_TH" height="16" rowSpan="1">
<textField>
<reportElement style="Custom_Currency" x="0" y="0" width="105" height="16" isRemoveLineWhenBlank="true"/>
<textFieldExpression><![CDATA[$P{taxTotal}]]></textFieldExpression>
</textField>
</jr:tableFooter>
<jr:detailCell style="Table_TD" height="16">
<textField>
<reportElement style="Custom_Currency" x="0" y="0" width="105" height="16" />
<textFieldExpression><![CDATA[$F{tax}]]></textFieldExpression>
</textField>
</jr:detailCell>
<style name="Custom_Text" mode="Opaque" backcolor="#EBEBEB" pattern="" isBlankWhenNull="true" fontSize="8">
<box topPadding="2" leftPadding="2" bottomPadding="2" rightPadding="2">
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
</style>
<style name="Custom_Currency" style="DF_Text" hTextAlign="Right" pattern="#,##0.00">
<box topPadding="2" leftPadding="4" bottomPadding="2" rightPadding="4"/>
</style>
and this is how it looks in action:
How should I declare paddings so that they work consistently in my whole report?
I have a report which has the columns Type,S.No,Date.Here the Type column will have the same value for all rows.So i just want to merge all the cells of Type column.I have referred the below link
Group several same value field into a single cell
and tried with their suggestion.But if i do like that i am getting like in below image.
Edit:
Below is the code i am using in my jrxml for merging the cells which have same data.
<field name="type" class="java.lang.String"/>
<group name="type">
<groupExpression><![CDATA[$F{type}]]></groupExpression>
</group>
In detail band i tried by creating the fake statictext behind the type textfield like below.
<staticText>
<reportElement x="0" y="0" width="121" height="20"/>
<box>
<leftPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement/>
<text><![CDATA[]]></text>
</staticText>
<textField>
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="121" height="20"/>
<box>
<topPen lineWidth="0.0"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.0"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{type}]]></textFieldExpression>
</textField>
But no use.
Tried by using printWhenExpression in type textfield like below.
<textField>
<reportElement x="0" y="0" width="121" height="20">
<printWhenExpression><![CDATA[$V{type_COUNT} == 1]]></printWhenExpression>
</reportElement>
<box>
<topPen lineWidth="0.0"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.0"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{type}]]></textFieldExpression>
</textField>
But no use.
If i add the bottom border for static text then the image looks like below.
Thank You.
Add the bottom border in GroupFooter band for group "type"
I have a main report and in the main report a sub report called this:
<detail>
<band height="50">
<subreport>
<reportElement x="0" y="1" width="802" height="49" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true"/>
<subreportParameter name="project_id">
<subreportParameterExpression><![CDATA[$P{project_id}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["subs/Project_planned.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
There is a problem in the subreport because text fields in the detail band are split up on multiple pages what doesn't look very nice. Is there an option to prevent text fields from splitting up to multiple pages when using the property isStretchWithOverflow
Current code of a text field
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement stretchType="RelativeToBandHeight" x="555" y="0" width="99" height="21" isPrintInFirstWholeBand="true" forecolor="#000000"/>
<box leftPadding="2">
<topPen lineWidth="1.0" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineColor="#000000"/>
</box>
<textElement verticalAlignment="Middle">
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[$F{logic}]]></textFieldExpression>
</textField>
Example on how it looks (sorry for the missing data):
Yes there is, but not on the text field. For the band the text field is in, you can set the Split Type to Prevent. if you set that on the Detail Band and the row needs to overflow to next page, it will move the entire row to the next page.
When the last entry in a page is too long, It will show in next page, when it show all the table line is missing.
This is the result:
How do I move the last record (no.26) to the next page, or how I can show the line?
You can put the staticText element without text behind the textField element. You should set stretchType property with RelativeToTallestObject value and isPrintWhenDetailOverflows property with true value.
The sample:
<detail>
<band height="20" splitType="Stretch">
<staticText>
<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="100" height="20" isPrintWhenDetailOverflows="true"/>
<box>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<text><![CDATA[]]></text>
</staticText>
<textField>
<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="100" height="20"/>
<box>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
</textField>
As result you will get the vertical border at the second page.
The result before adding the second staticText was (the vertical border at the second page is absent):
Better way is to ensure, that new items in Detail band (or any band) will be generated on next page by setting, but not on the text field. For the band the text field is in, you can set the Split Type to Prevent. if you set that on the Detail Band and the row needs to overflow to next page, it will move the entire row to the next page.
I've written jasper specification to generate PDF from a table data source. This is working fine. Now i have to add few more columns and the report is now not looking good. I'm now thinking if I can squeeze in the column names in multiple lines like the one below
Maintenance Date
to
Maintenance
Date
Is it possible to achieve this in Jasper?
Regards,
Paul
Are your column names hard-coded? Do you just need to change "Maintenance Date" to "Maintenance\nDate" to have a carriage return?
Note: you cannot add a "\n" character to a Static Text element. You need to use a Text Field. Fortunately, you can just right-click on a Static Text element in iReport and transform it to a Text Field.
I guess that might solve it. If not, then you may need to make the question clearer.
If you are using JasperReports API you can use this sample:
//Detail
band = new JRDesignBand();
band.setHeight(40);
JRDesignStaticText staticText = new JRDesignStaticText();
staticText.setX(0);
staticText.setY(0);
staticText.setWidth(60);
staticText.setHeight(20);
staticText.setMode(ModeEnum.OPAQUE);
staticText.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
staticText.setStyle(boldStyle);
staticText.setText("ID: ");
staticText.getLineBox().getLeftPen().setLineWidth(1);
staticText.getLineBox().getTopPen().setLineWidth(1);
staticText.getLineBox().setLeftPadding(10);
band.addElement(staticText);
textField = new JRDesignTextField();
textField.setX(60);
textField.setY(0);
textField.setWidth(200);
textField.setHeight(20);
textField.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
textField.setStyle(normalStyle);
expression = new JRDesignExpression();
expression.setValueClass(java.lang.Integer.class);
expression.setText("$F{Id}");
textField.setExpression(expression);
textField.getLineBox().getTopPen().setLineWidth(1);
textField.getLineBox().getRightPen().setLineWidth(1);
textField.getLineBox().setLeftPadding(10);
band.addElement(textField);
staticText = new JRDesignStaticText();
staticText.setX(0);
staticText.setY(20);
staticText.setWidth(60);
staticText.setHeight(20);
staticText.setMode(ModeEnum.OPAQUE);
staticText.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
staticText.setStyle(boldStyle);
staticText.setText("Name: ");
staticText.getLineBox().getLeftPen().setLineWidth(1);
staticText.getLineBox().getBottomPen().setLineWidth(1);
staticText.getLineBox().setLeftPadding(10);
band.addElement(staticText);
textField = new JRDesignTextField();
textField.setStretchWithOverflow(true);
textField.setX(60);
textField.setY(20);
textField.setWidth(200);
textField.setHeight(20);
textField.setPositionType(PositionTypeEnum.FLOAT);
textField.setStyle(normalStyle);
expression = new JRDesignExpression();
expression.setValueClass(java.lang.String.class);
expression.setText("$F{FirstName} + \" \" + $F{LastName}");
textField.setExpression(expression);
textField.getLineBox().getRightPen().setLineWidth(1);
textField.getLineBox().getBottomPen().setLineWidth(1);
textField.getLineBox().setLeftPadding(10);
band.addElement(textField);
((JRDesignSection) jasperDesign.getDetailSection()).addBand(band);
The result will be:
This is almost identical to this snippet of jrxml file:
<detail>
<band height="40" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="60" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
</box>
<textElement/>
<text><![CDATA[ID: ]]></text>
</staticText>
<textField>
<reportElement x="60" y="0" width="200" height="20"/>
<box leftPadding="10">
<topPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{Id}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="20" width="60" height="20"/>
<box leftPadding="10">
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
</box>
<textElement/>
<text><![CDATA[Name: ]]></text>
</staticText>
<textField>
<reportElement x="60" y="20" width="200" height="20"/>
<box leftPadding="10">
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{FirstName} + " " + $F{LastName}]]></textFieldExpression>
</textField>
</band>
</detail>