J
jc1771
Hi all,
I'm getting an error with my JSTL tags that is really driving me nuts.
I have a HashMap of objects that needs to be sorted by one of the
elements in the object (the Comparable interface has been coded and
works fine) before it is displayed on the JSP page. However I don't
need to sort the data unless it's being displayed in a report, so I
only want to sort it once when the report is run. Here's the code I
am using to retreive a sorted Vector from the class:
public Vector getSortedTransactions(){
if(!isSorted){
//sort the map into a vector
sortedTransactions = new Vector(transactionsMap.values());
Collections.sort(sortedTransactions);
isSorted == true;
}
return sortedTransactions;
}
Here's the JSTL call I make:
<c:forEach items='${seriesBean.sortedTransactions}' var='xac'>
<tr> ...
And here's the error:
An error occurred while evaluating custom action attribute "items"
with value "${seriesBean.sortedTransactions}": An error occurred while
getting property "sortedTransactions" from an instance of class XXXXX
What is frustrating is that it works fine if I change the getter to:
public Vector getSortedTransactions(){
return sortedTransactions = new Vector(transactionsMap.values());
}
However obviously the vector won't be sorted.
This works fine when I run the output to the console, but not to the
JSP tags. Does the JSTL have a rule I can't find anywhere about not
allowing logic in a getter? Does anyone else have any ideas how to do
this? I guess I could sort the vector every time a value is entered
into the hashmap, but that doesn't seem too efficient to me.
Thanks!
John
I'm getting an error with my JSTL tags that is really driving me nuts.
I have a HashMap of objects that needs to be sorted by one of the
elements in the object (the Comparable interface has been coded and
works fine) before it is displayed on the JSP page. However I don't
need to sort the data unless it's being displayed in a report, so I
only want to sort it once when the report is run. Here's the code I
am using to retreive a sorted Vector from the class:
public Vector getSortedTransactions(){
if(!isSorted){
//sort the map into a vector
sortedTransactions = new Vector(transactionsMap.values());
Collections.sort(sortedTransactions);
isSorted == true;
}
return sortedTransactions;
}
Here's the JSTL call I make:
<c:forEach items='${seriesBean.sortedTransactions}' var='xac'>
<tr> ...
And here's the error:
An error occurred while evaluating custom action attribute "items"
with value "${seriesBean.sortedTransactions}": An error occurred while
getting property "sortedTransactions" from an instance of class XXXXX
What is frustrating is that it works fine if I change the getter to:
public Vector getSortedTransactions(){
return sortedTransactions = new Vector(transactionsMap.values());
}
However obviously the vector won't be sorted.
This works fine when I run the output to the console, but not to the
JSP tags. Does the JSTL have a rule I can't find anywhere about not
allowing logic in a getter? Does anyone else have any ideas how to do
this? I guess I could sort the vector every time a value is entered
into the hashmap, but that doesn't seem too efficient to me.
Thanks!
John