Po tym, jak borykałem się z tym przez kilka godzin ... i szukałem rozwiązania w Internecie ... Przyjąłem rozwiązanie (fora oświecające były następujące: one i two).
Najpierw należy zdefiniować klasę pomocnika języka Java, która pozwala obliczyć operację arytmetyczną, w moim przypadku operację Sum. I zdefiniowano następujące klasy:
package reports.utils;
import java.util.Map;
/**
* Utility that allows you to sum Integer values.
*/
public class SumCalculator {
/**
* Stores a map of {@code SumCalculator} instances (A Map instance per thread).
*/
private static final ThreadLocalMap<String, SumCalculator> calculatorsIndex = new ThreadLocalMap<>();
/**
* The sum total.
*/
private int total = 0;
/**
* No arguments class constructor.
*/
private SumCalculator() {
super();
}
/**
* Instance a new {@code SumCalculator} with the given ID.
*
* @param id {@code SumCalculator}'s ID
* @return the new {@code SumCalculator} instance
*/
public static SumCalculator get(String id) {
Map<String, SumCalculator> map = calculatorsIndex.get();
SumCalculator calculator = map.get(id);
if (calculator == null) {
calculator = new SumCalculator();
map.put(id, calculator);
}
return calculator;
}
/**
* Destroy the {@code SumCalculator} associated to the given ID.
*
* @param id {@code SumCalculator}'s ID
* @return {@code null}
*/
public static String destroy(String id) {
Map<String, SumCalculator> map;
map = calculatorsIndex.get();
map.remove(id);
if (map.isEmpty()) {
calculatorsIndex.remove();
}
return null;
}
/**
* Resets the {@code SumCalculator} total.
*
* @return {@code null}
*/
public String reset() {
total = 0;
return null;
}
/**
* Adds the given integer value to the accumulated total.
*
* @param i an integer value (can be null)
* @return {@code null}
*/
public String add(Integer i) {
this.total += (i != null) ? i.intValue() : 0;
return null;
}
/**
* Return the accumulated total.
*
* @return an Integer value (won't be null, never!)
*/
public Integer getTotal() {
return this.total;
}
}
package reports.utils;
import java.util.HashMap;
import java.util.Map;
/**
* Thread Local variable that holds a {@code java.util.Map}.
*/
class ThreadLocalMap<K, V> extends ThreadLocal<Map<K, V>> {
/**
* Class Constructor.
*/
public ThreadLocalMap() {
super();
}
/* (non-Javadoc)
* @see java.lang.ThreadLocal#initialValue()
*/
@Override
protected Map<K, V> initialValue() {
return new HashMap<>();
}
}
drugie, w raporcie jaspisu, trzeba zdefiniować cztery pola tekstowe:
1) tekst dziedzinie, która iniatializes swój kalkulator; powinno to być (najlepiej) w sekcji tytułowej raportu i powinno mieć takie wyrażenie: SumCalculator.get("$V{SUB_REPORT_RETURN_VALUE}").reset()
. To pole tekstowe powinno mieć czas oceny: TERAZ.
2) Pole tekstowe, które wywołuje funkcję przyrostu (tj SumCalculator.get("$V{SUB_REPORT_RETURN_VALUE}").add($V{SUB_REPORT_RETURN_VALUE})
To pole tekstowe będzie przebywać w swoim szczegół zespołu, po elementu podraportu, a powinien mieć czas oceny:. BAND (jest to bardzo ważne !!)
3) Pole tekstowe, które drukuje sumę kalkulatorów. To pole tekstowe będzie znajdować się w Twoim podsumowaniu, będzie oceniane na TERAZ. Jego wyrazem będzie: SumCalculator.get("$V{SUB_REPORT_RETURN_VALUE}").getTotal()
4) Pole tekstowe, które niszczy kalkulator. To pole tekstowe będzie również znajdować się w twoim podsumowaniu i musi pojawić się po polu tekstowym 3. Pole tekstowe powinno mieć wyrażenie takie jak: SumCalculator.destroy("$V{SUB_REPORT_RETURN_VALUE}")
.To pole tekstowe powinno mieć czas oceny: TERAZ.
Również pola tekstowe: 1, 2 i 4 powinny mieć atrybut "Pusty, gdy wartość Null", więc nigdy nie będą drukowane (dlatego te operacje java zawsze zwracają wartość null).
I to wszystko. Następnie raport może wyglądać następująco:
Mam ten sam problem z tym, że tęsknię nie tylko pierwszy sub-raportu wartości zwracanej. – Gustavo