Jump to content
We've recently updated our Privacy Statement, available here ×

method evaluation and dynamic textfield


jonataswingeter

Recommended Posts

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

  • Replies 15
  • Created
  • Last Reply

Top Posters In This Topic

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,

Robin

Post edited by: rsilver@bfm.bm, at: 2006/11/21 12:24

Link to comment
Share on other sites

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 like

Code:

<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,

Lucian

Post edited by: lucianc, at: 2006/11/21 12:47

Link to comment
Share on other sites

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...