Hello,
i need to create two o more copy of a report where for each copy i need to change the value of a "label"
accordingly some rules from the final user. Currently I added a parameter to the report and i pass the desired value.
For example i need to put only the following text: "Copy for me", "Copy for XXX YYY", ecc...
and due the great quantity of data/processing time involved during the fill i need to wait for a long time for each fill.
Is possible to change the value without re-fill the entire report?
thank for you help
Stefano
1 Answer:
Hi,
yes it is.... we do so when numbering our copies (e.g. Copy X of Y) withour regenerating the whole printout.
So try the way we do (and this is working fine for at least 3 years) :-)
- create a textfield where you later want to insert your copytext
- set the textfield expression to " " so just a space character
- make sure that the text you'll insert later will fit into the field (make it wide enough)
- set the anchorname-expression to something like "COPYFIELD" (perhaps you can also use the element-key attribute, this should be readable also in JasperPrint-Object (when we started it wasn't, that's why the way via the HyperLinkAnchorNameExpression)
- set the "RemoveLineWhenBlank" to FALSE (important!!!)
now if you have your JasperPrint you just need to parse that object and set the text .. see my method below.
hth
C-Box
Code: |
public static JasperPrint setCopyTextOnJasperPrint(JasperPrint jrPrint, String copyText, int currentCopy, int totalCopy) throws Exception { if (jrPrint != null && jrPrint.getPages() != null && jrPrint.getPages().size() > 0 && copyText != null) { java.util.List<JRPrintPage> pageList = jrPrint.getPages(); for (int i = 0; i < pageList.size(); i++) { JRPrintPage page = pageList.get(i); java.util.List<JRPrintElement> elemList = page.getElements(); for (int j = 0; j < elemList.size(); j++) { if (elemList.get(j) instanceof JRBasePrintText) { JRBasePrintText elem = (JRBasePrintText) elemList.get(j); if ("SYSTEM_KopieFeld".equalsIgnoreCase(elem.getAnchorName())) { elem.setText(copyText); } else if ("SYSTEM_KopieX".equalsIgnoreCase(elem.getAnchorName())) { elem.setText(String.valueOf(currentCopy)); } else if ("SYSTEM_KopieY".equalsIgnoreCase(elem.getAnchorName())) { elem.setText(String.valueOf(totalCopy)); } } } } return jrPrint; } else { throw new IllegalArgumentException("Ungültiges PrintObjekt und/oder KopieText übergeben!"); } }</td></tr></tbody></table> |