Domanda

I'm working on a PDF in which I'm trying to have a checkbox in front of each line of a "list" JR component.

I already have some editable fields (text and radio) in my report, in the 'Title' section; everything goes well.

To do that, I use "generic elements" and have some handlers written in Java who generate for example iText TextField in a rectangle (com.lowagie.text.Rectangle.Rectangle), defined like this ('element' is the current generic element, of type JRGenericPrintElement):

element.getX(), 
exporterContext.getExportedReport().getPageHeight() - element.getY(),
element.getX() + element.getWidth(), 
exporterContext.getExportedReport().getPageHeight() - element.getY() - element.getHeight()

The 'generic element' is defined like this in my .jrxml :

<genericElement>
    <reportElement uuid="ec205c41-afe2-44fd-a8b3-03e2d4b07ce6" x="72" y="132" width="143" height="25"/>
    <genericElementType namespace="http://namespace" name="simpleEditableTf"/>
    <genericElementParameter name="name">
    <valueExpression><![CDATA["matricule"]]></valueExpression>
    </genericElementParameter>
</genericElement>

I would like to use the same code to define the position of my list checkboxes, but it seems that in the case the generic element is used into a list, the element.getX() and element.getY() methods return the coordinates relatively to the list component.

So rather to have the coordinates of the element in the page (eg. X=50,Y=200) I have these relative to the list component itself (X=4,Y=7); so it's impossible to set the element correctly.

Here is the code of the list element, including the generic element.

<componentElement>
    <reportElement uuid="0aa17cac-d5e2-4592-ba0d-ab8e25cc989b" x="10" y="10" width="476" height="23" forecolor="#366798"/>
    <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
        <datasetRun subDataset="item_ab" uuid="3c25ec33-3a70-497f-b234-0d5ea64cabcf">
            <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}.subDataSource("//item_ab")]]></dataSourceExpression>
        </datasetRun>
        <jr:listContents height="23" width="476">
            <textField isStretchWithOverflow="true">
                <reportElement uuid="0158660b-3ab1-4149-8599-77824c64082f" x="20" y="1" width="420" height="20"/>
                <textElement verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{libelle_ab}]]></textFieldExpression>
            </textField>
            <genericElement>
                <reportElement uuid="12c64be4-27dd-4aa2-8d50-f412e25d9805" x="4" y="7" width="9" height="9"/>
                <genericElementType namespace="http://namespace" name="checkBox"/>
            </genericElement>
        </jr:listContents>
    </jr:list>
</componentElement>  

Could someone tell me if I did something wrong? Is it a bug?

È stato utile?

Soluzione

In your generic element handler, add JRPdfExporterContext.getOffsetX()/Y to the position of the element, that is use element.getX() + exporterContext.getOffsetX() everywhere instead of element.getX().

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top