Print List<String> each element in new field - jasper-reports

I am fresh in JasperReports and I'm having problems solving an issue.
I have a report and a field $F{therapies} that is type of List<String>. If I print this field, the whole List is printed as a single String. Is it possible to print each element of the list in a new line or better - as a new Text Field.
If I try, for instance, $F{therapies}.get(1), it prints correctly the element at position 1. But since the size of List isn't constant I can't solve it that way.
I hope you understand what I want to achieve . Somehow printing List<String> per element.

I solved my problem using subreport and passing List as a datasource.
Here is a link: Passing the List of primitive type objects as datasource for subreport

Related

How to remove a piece in a string

So I am making a quest system, and I want to randomly choose a quest, but i dont want it to choose the same one again.
Here is the piece on code for the string.
I cant find any good answer.
This is a more simple line of code.
string[] QuestChoose = new string[] {"Quest1", "Quest2", "Quest3"};
3 methods come to mind:
Convert to a List and call Remove().
Write null into the array after having read the quest and when selecting a quest, always search for the next suggestion if null was selected.
Keep a separate data structure like a HashSet<int> where you add the index in the array whenever a quest has been used. Then check for Contains on your ID when selecting.
You really ought to use lists if you want to dynamically add/remove elements from your set.
Instead of:
string[] QuestChoose = new string[] {"Quest1", "Quest2", "Quest3"};
try using:
List<string> QuestChoose = new List<string> { "Quest1", "Quest2","Quest3"};
You can add elements by calling QuestChoose.Add("Quest4");
Or remove an element by calling: QuestChoose.Remove(ItemNumber);
Where as "ItemNumber" is the index of the string you want to remove. For example; Calling QuestChoose.Remove(0); will remove the first item in the list, which in this case would be "Quest1"

The column footer band not to print on last page

How can I achieve this? I also tried using "print when expression" with condition
new Boolean($V{PAGE_NUMBER}.intValue() < $V{PAGE_COUNT}.intValue())
but sadly it does not work. Please help me.
This print when expression works fine for me $V{PAGE_NUMBER}<$V{PAGE_COUNT}. It works when applied to either the column footer band or the footer band element (I used static text).
Comparing PAGE_NUMBER and PAGE_COUNT is like comparing apples and oranges.
The Built-In Variables
PAGE_NUMBER: At every iteration it contains the number of the pages that compose the report.
PAGE_COUNT: Contains the number of record processed in the current page
To answer the question: JasperReports knows a band type "Last Page Footer" (wiki description) to define a different footer on the last page.
(Your problem might already be solved. But I stumbled upon this two year old question while having a similar issue and wanted to leave a hint, that one should not compare those variables.)

Issue with passing field variable to subreport from master report

I am trying to do a simple expression in iReport, but whatever I try seems hasn't given me which I expected. It seems like such a simple thing to do, but I couldn't understand what's happening with my code.
All I'm trying to do is show a subreport when the value of an string field is a simple word like "VALUE". I am using the Print When Expression for the subreport control, however I'm not able to the see or reproduce this text with this expression. For me seems that I'm not passing well the parameters I wan't to use to do the print when expression in the subreport from the master report.
Is a disclaimer, so in master report I have a simple subreport, with the same conection from master and one parameter called Entity = "_id.Entity" (we use mongodb to get the fields for the report with a $group) and in the subreport part I have 2 text fields, the first one have the print when expression when P{Entity}.equals("VALUE"), the second one don't have any condition so this works perfectly, but the textfield with the condition doesn't work.
Any help would be appreciated. Thanks.

JavaFX error: incompatible types - Object cannot be converted to Node

I have defined 3 labels in a FXML file within a grid pane. I am trying to read the following XML file and display the labels present in the file in a grid pane. The numerical values in the XML file denotes the row & column position.
<data>
<lbl1>0,0</lbl1>
<lbl2>0,1</lbl2>
<lbl3>0,2</lbl3>
</data>
I have added all the elements to the HashMap and then retrieve it to be displayed. Firstly, I added all the three labels one by one as follows:
hm.put("lbl1", eElement.getElementsByTagName("lbl1").item(0).getTextContent());
hm.put("lbl2", eElement.getElementsByTagName("lbl2").item(0).getTextContent());
hm.put("lbl3", eElement.getElementsByTagName("lbl3").item(0).getTextContent());
Then I display them as follows:
grid.add(lbl1, Integer.parseInt(hm.get("lbl1").toString().split(",")[0]),Integer.parseInt(hm.get("lbl1").toString().split(",")[1]));
grid.add(lbl2, Integer.parseInt(hm.get("lbl2").toString().split(",")[0]),Integer.parseInt(hm.get("lbl2").toString().split(",")[1]));
grid.add(lbl3, Integer.parseInt(hm.get("lbl3").toString().split(",")[0]),Integer.parseInt(hm.get("lbl3").toString().split(",")[1]));
The above code works well without any issues and I can see the labels on the grid.
Now, instead of adding the labels one by one, I added all of them in a single statement through a 'for' loop as shown below:
if (!eElement.getTagName().toString().equals("data"))
hm.put(eElement.getTagName(), eElement.getTextContent());
If I try to display the label, for example:
grid.add(hm.get("lbl1"),0,0);
I get an error:incompatible types - Object cannot be converted to Node.
If I try to typecast:
grid.add((javafx.scene.Node) hm.get("lbl1"),0,0);
I get an error:java.lang.ClassCastException: java.lang.String cannot be cast to javafx.scene.Node
If I print the hashmap entries, the following output is shown:
lbl1=0,0, lbl2=0,1, lbl3=0,2
How to fix this error? Is there any other way in which I can add all the elements in a single statement and then display them?
in your imports add:-
import javafx.scene.control.Label;
I suspect that the current import is from awt.
From your sample code, I guess that hm is an instance of Map<String, String>
So, when you call hm.get("lbl1") , you get a String.
You're trying to add this String to a GridPane, but the add() method is expecting a javafx.scene.Node. That's why you get a an error "incompatible types".
Instead, you should add your instances of javafx.scene.control.Label (lbl1, lbl2, lbl3)

iReport sum of two measures

I'm having problem with JasperReports report by getting sum of two fields.
I have created so far variables that holds fields "TareWeight" variable that is casting values from double to float
new Float($F{EquipmentTareWeightKg})
"CargoWt" variable that is casting from string to float, etc...
Float.parseFloat($F{UfvFlexString03})+Float.parseFloat($F{UfvFlexString04})
So now I have two variables which I can manipulate with.
The problem starts when I wish to do a "recap" using crosstab. I have setup two groups that is done with wizard, and added another in crosstab. (please refer to the printscreen below)
And now, I have created under measures SumOf Tare that is using variable TareWt, and SumOfCargoWt that is using variable CargoWt.
I have tried to create another Measure SumOfGrossWt that would do a sum of variables TareWt + CargoWt but I have got some nonsense values.
I have tried to do another approach by creating variable GrossWt that would basically do exact the same thing as previous attempt
$V{Tare}+$V{CargoWt}
or use an variable: GrossWt
$V{Tare}+$V{CargoWt} or new Float($F{EquipmentTareWeightKg})+(Float.parseFloat($F{UfvFlexString03})+Float.parseFloat($F{UfvFlexString04}))
None of these actually worked: (Sum should be done by "Sum Of Tare"+ "Sum of CargoWt" = "Sum of GrossWt") plese refer to the second picture.
Here is a complete jrxml code/file:
jrxml file
save it as *.jrxml
Can please someone help me find a solution? how can I sum those two measure fields and get correct values?
Since CargoWt field had some null values in database, addition float value with null is equal to null, so the only value which was displayed on report are the one that had values for CargoWt, all others with null value were "ignored".