jonataswingeter Posted November 21, 2006 Share Posted November 21, 2006 Hi People. I'm enthusiast for jasper and newer here, hello for all. I'm facing a problem I don't found solution. 1) I have a field $F{campo} that need be evaluated in runtime, cause I need change the textField to Bold or not, depending of the case.I wanna know if setting both textfield (one with bold and other not) and alternate its visibility from $F{campo} changes is the only one solution.Can I do something like quickreport of delphi, where I set the textfield to bold at runtime according field value? 2) I have a method that is called by Scriptlet in a group. The group has a evaluation expression to make grouping from SQL command, therefore, the method is called not just on group evaluation, but each detail record show it has been called. Is it a bug or may be a something wrong no xml? Thanks. Jônatas Link to comment Share on other sites More sharing options...
rsilverns.sympatico.ca Posted November 21, 2006 Share Posted November 21, 2006 1. There are two ways to do this... A. place the field twice in the same position, one field is bold, the other isn't. Then use a printWhenExpression on each field that is a reciprocal of the other. (i.e. field1: new Boolean($F{campo}.equals("nonbold")) and field2: new Boolean(!$F{campo}.equals("nonbold")) B. Use conditional styles. TO use these, set the flag on the element isStyledText = true. And then place xml inline in the field to denote the styling. Example: $F{campo}.equals("boldvalue")?("<style isBold="true">" + ($F{camp}) + "</style>"):$F{campo} 2. Not too sure on this one, but try moving the call to the group header, if its called with every record, its probably related to the detail band, the header would only be present once for each time the group changes. HTH,RobinPost edited by: rsilver@bfm.bm, at: 2006/11/21 12:24 Link to comment Share on other sites More sharing options...
jonataswingeter Posted November 21, 2006 Author Share Posted November 21, 2006 Hi Robin, thanks for your solution. I'll try it. Link to comment Share on other sites More sharing options...
lucianc Posted November 21, 2006 Share Posted November 21, 2006 rsilver@bfm.bm wrote: B. Use conditional styles. TO use these, set the flag on the element isStyledText = true. And then place xml inline in the field to denote the styling. Example: $F{campo}.equals("boldvalue")?("<style isBold="true">" + ($F{camp}) + "</style>"):$F{campo} A small note regarding the terminology: this is not what we usually call "conditional styles"; this is usually referred to as styled text (dynamic and containing a condition in this case, hence the terminology confusion). A solution using conditional styles would look something likeCode:<style name="textStyle"> <conditionalStyle> <conditionExpression>new Boolean($F{campo}.equals("bold"«»))</conditionExpression> <style isBold="true"/> </conditionalStyle></style>...<textField> <reportElement style="textStyle" .../> ...</textField> Regarding your second question, could be more specific about the expression that calls the scriptlet method (is it the group expression or some other expression)? A relevant JRXML fragment wouldn't hurt. Regards,LucianPost edited by: lucianc, at: 2006/11/21 12:47 Link to comment Share on other sites More sharing options...
jonataswingeter Posted November 22, 2006 Author Share Posted November 22, 2006 Hi Lucian. firstly I thank you for your help. I've a report made at runtime, using JRDesign.The group band is added according my logic and it has a group expression.Inside group header, it has a textfield with textexpression, that returns a method $P{REPORT_SCRIPTLET}.getTotal().The group expression is evaluated correctly, just on groupexpression $F{representante} changes, but the method getTotal() is executed every row inserted in detail.I debugged the application and the method is called every row request, processed by callBeforeDetailEval().Note I don't have the method inserted in some event of scriptlet, but only the method declaration to be called by report. It is a stranger behavior. I don't have time to look sources yet, but I cam check it too. Regards, Jônatas Link to comment Share on other sites More sharing options...
jonataswingeter Posted November 22, 2006 Author Share Posted November 22, 2006 Hi Lucian, How could I inserted the XML tags through runtime? I tried something like that: Code: JRDesignStyle jrStyle = new JRDesignStyle(); JRDesignConditionalStyle jrconditionalStyle; { jrconditionalStyle = new JRDesignConditionalStyle(); JRDesignExpression expressao; { ResourceBundle rb = ServiceLocator.getInstance().getResourceMensagem(); expressao = new JRDesignExpression(); expressao.setValueClass(Boolean.class); expressao.addTextChunk("new Boolean(true)"«»); } jrconditionalStyle.setConditionExpression(expressao); jrconditionalStyle.setBold(true); } jrStyle.addConditionalStyle(jrconditionalStyle); jrStyle.getConditionalStyleList().add(jrconditionalStyle); jrStyle.setName("formaNegrito"«»);[/ciode]But it didn't create the tags that you supose in your last post.Thanks.Jônatas Link to comment Share on other sites More sharing options...
rsilverns.sympatico.ca Posted November 22, 2006 Share Posted November 22, 2006 Distinction noted.. thx. lucianc! Cheers,Robin Link to comment Share on other sites More sharing options...
lucianc Posted November 22, 2006 Share Posted November 22, 2006 Regarding your code: did you do jasperDesign.addStyle(jrStyle)? Also, why do you add the conditional style twice? Regards,Lucian Link to comment Share on other sites More sharing options...
jonataswingeter Posted November 22, 2006 Author Share Posted November 22, 2006 Hi Lucian. I added just in component textfield.If I insert into jasperDesign, the xml generated returns <style name="formaNegrito" ... /> and <style name="formaNegrito1" .../> It repeats de code. What is correct? In both case, the conditional tag isn't created, but just style tag with nothing more. Thanks. Jônatas Link to comment Share on other sites More sharing options...
lucianc Posted November 22, 2006 Share Posted November 22, 2006 <conditionalStyle> only appears in JRXML (report design) files, and not in XML exports of print reports. Conditional styles generate print styles like the "formaNegrito1" style you saw in your filled report. Regards,Lucian Link to comment Share on other sites More sharing options...
jonataswingeter Posted November 22, 2006 Author Share Posted November 22, 2006 Hi Lucian. I understood. I put the code and textField has that instance (JRStyle) but on PDF view nothing changes or appear. I made a test with iReport and it runs, but with coding no. Have you any idea? Link to comment Share on other sites More sharing options...
lucianc Posted November 22, 2006 Share Posted November 22, 2006 You need to also set a bold PDF font. See the Fonts sample on this page. Link to comment Share on other sites More sharing options...
jonataswingeter Posted November 22, 2006 Author Share Posted November 22, 2006 OK lucian. it rocks now. Thank for your help. Jônatas Link to comment Share on other sites More sharing options...
jonataswingeter Posted November 22, 2006 Author Share Posted November 22, 2006 Lucian. I've started a small project to help programmer developer reports. it consist to determine, by a class configurator, the field avaiable in report. After it, a datasource is associated with the report and each Bean of the List can be conected to the field set definition. At this way, isn't needed to implement XML, because the report is simple, as a template.1) You tell the fields you want in report;2) customize each field, if needed (Sum, Total, Count, Alignment, Pattern, etc);3) Associate the datasource. Ready.It makes sense for many simple report. I recently did it at my work and now I'm doing a version more powerful and consistence. I tried publish a new project at jasperforge (I don't know it its ok), but if you have interest, contact me. It will be available under GPL. Link to comment Share on other sites More sharing options...
lucianc Posted November 24, 2006 Share Posted November 24, 2006 We would be glad to host your project on JasperForge. Read this quick view on how to register a new project. If you have questions/suggestions regarding JasperForge, you can post them on this forum. Thank you,LucianPost edited by: lucianc, at: 2006/11/23 16:17 Link to comment Share on other sites More sharing options...
jonataswingeter Posted November 25, 2006 Author Share Posted November 25, 2006 Hi Lucian. I've already requested a new project on jasperforge.org. Thanks. Jônatas Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now