JasperReports: Changing a Pattern Value based on a Field - jasper-reports

I have a field that contains the type of data coming in on the detail fields. It is either an Integer or an Currency value. [An Integer is not a Currency value] The field that is outputing the value is typed as a double, and the text field is currently ####.##.
Is there any way that the pattern can change based on a field value [the field value that makes this either or is a boolean.

Now, at least in version 4.7.1, there is an "Patern Expr."
ex:
$F{Field}.abs().compareTo( new BigDecimal(1) ) < 0 ? "0.0#####E0#" : "#,##0.00"

Every Jasper report can access all classes available on the classpath. Create a static method which will accept an Object as an argument, check if it is Currency or Integer and return well formatted String value. Import the class in the report and invoke the formatting method from the field.

Related

Validate a date range in XSD for either date or dateTime?

I have an element that accepts either a date value or a dateTime value. Right now the xsd for the element looks like this:
<xs:simpleType name="sTidpunkt">
<xs:union memberTypes="xs:date xs:dateTime"/>
</xs:simpleType>
How can I expand this to validate that the date part of the date or dateTime value is within a certain range? For example it has to be later than 1980-06-01 and earlier than 1990-06-01.
Thanks!
Reference information for XSD simple types is here: https://www.w3.org/TR/xmlschema-2/#dateTime
Based on that specification, I recommend the following:
Declare two new global simple type definitions: (e.g. myDate and myDateTime)
Add facets to those simple type definitions to limit the values in whatever way you require.
Change your memberTypes attribute to refer to the new simple types.

What are rawToValue and valueToRaw in Extjs pickerfield?

I'm using Extjs 6.5. I want to implement a picker that have 4 fields: String, Number, Combobox, Color.
I want to save value as an object as follow:
{
string: 'its my name',
number: 12,
combobox: 'combo',
color: 'ffffffff'
}
That means when you call field.getValue() it return above object, but In field textfield only string value is shown. User can expand picker and edit some fields. I can't understand whats rawToValue and valueToRaw in Ext.form.field.picker? What are these?
Basically picker is extend from field and this field have both methods valueToRaw & rawToValue
Hierarchy of extend of picker you can see here ExtJs pickerfield
rawTovalue converts a raw input field value into a mixed-type value that is suitable for this particular field type. This allows controlling the normalization and conversion of user-entered values into field-type-appropriate values, e.g. a Date object for Ext.form.field.Date, and is invoked by getValue.
It is up to individual implementations to decide how to handle raw values that cannot be successfully converted to the desired object type.
valueToRaw converts a mixed-type value to a raw representation suitable for displaying in the field. This allows controlling how value objects passed to setValue are shown to the user, including localization. For instance, for a Ext.form.field.Date, this would control how a Date object passed to setValue would be converted to a String for display in the field.

Formatting a string in jaspersoft?

In my report I have a string field with some numeric value, for example 123102,6. I would like to display 123 102,60 in my report.
Formatting numbers is a bugger in Java in general but gets even trickier with Jasper.
If your report works with a Locale that provides the space as the number group separator (like, for example, Locale.FRANCE does), then all you need to do is specify #,##0.00 as the value of the Pattern property of your field.
If that is not the case, or you are using several Locales, or you are resolving them at runtime, then the simplest way to solve your problem is to provide this:
new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(Locale.FRANCE))
.format(Double.valueOf($F{your_field_name}))
as the value of the Text Field Expression property of your field.

How make default value validation?

I have created an input(text) element which has a default value 'Email'. Label to field was deleted.
How to validate the text field to see if it contains the default value?
Thnx!
You can use the Identical validator, passing your default value as the string to compare against.

JasperReports: default value instead of 'null'

Is there any way to set a default value to a field in a report? I have a lot of String fields in a report and would like them to display "0,00" when they're null.
Supposing the field name is "value", in the "Text Field Expression", write:
($F{value} != null) ? $F{value} : "0.00"
You can also select "Blank when null" in the properties of the text field if you want that. Other options are more flexible but this does the trick very quick and easy.
medopal's answer is good, but 2 additions:
1) You can make the syntax shorter:
($F{field_name}) ? $F{field_name} : "0.00"
2) Make sure your "else" data is of the same class as the field's value, otherwise you'll get errors when it tries to coerce numbers into string, etc. etc. This was something that, as I started out, I mixed up.
Did you try set a pattern in the text field?
If you are using iReport this can be found in the properties for the text field in the Text Field Properties section.
Try something along the lines of ###0.00 to represent 1234.56, which would always display 0.00 even if it is null.
This is the easiest way is to use Coalesce() or NVL() function of database in your data-source query to restrict null data on your report.
But it depends on if you are allowed to change the datasource query or not. If not then you can go for other solutions provided in previous answers.