View Full Version : how can i replace specific value with other character?

09-09-2002, 04:56 AM
Now i'm using JFreeReport 0.7.5. Thank you it's really wonderful.
I have a question about JFreeReport.
in "ITEM" i list one field with contain integer but i don't want it to show value 0 (zero) , i just want it to show "-". how can i do that? I don't want to change database structure to keep null value. Please help me out.

Thank in advance.
P.S. Thank you Thomas this class REALLY HELPFUL.


09-09-2002, 07:56 AM

for JFreeReport versions prior to 0.7.6 you will have to write your own function for this feature. To make life easier upgrade to version 0.7.6, you get TextFormatExpression which does what you want.

This expression wraps a java.text.MessageFormat object and returns the formated String to the element. The formating you want to do is covered by the choice-format of java. The choiceformat can only be used with numeric values.

<expression name="expr" class="com.jrefinery.report.function.TextFormatExpression">
<property name="pattern">Invoice for your order from {0, choice, 1#one| 2#{0}}</property>
<property name="0">count</property>

The message format pattern used in this example is "Invoice for your order from {0, choice, 1#one| 2#{0}}" and {0} is replaced by the value of the field, function or expression named "count".

The message pattern contains a choice format pattern for value {0}, the choice format pattern string is : "1#one| 2#{0}" and defines that values of "1" should be replaced by the string "one" and all values greater or equal to 2 should be printed as they are.

Just replace the expression contained in report3.xml with the above definition to see the example working.

Have more fun,
said Thomas

09-17-2002, 12:21 AM
ahhh Thank you very much! It's work.. but i have to change all of my layout. it's seem that my xml's layout in 0.7.5 is screwed up when using 0.7.6 ..
But thank you :) your project is really cool