JSTL - Conditional Logic in a getter

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
 
M

Mark Meyer

In said:
isSorted == true;

I think you mean

isSorted = true;

I don't know if this fixes your problem, but it couldn't hurt.

Mark Meyer (e-mail address removed)
Raytheon Voice (972)344-0830 Fax (972)344-6840
 
J

jc1771

Mark Meyer said:
I think you mean

isSorted = true;

I don't know if this fixes your problem, but it couldn't hurt.

Mark Meyer (e-mail address removed)
Raytheon Voice (972)344-0830 Fax (972)344-6840

Oops - thanks for catching that. I must have added it when I was
writing the mail. Thanks!

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Logic Problem with BigInteger Method 2
View page without JSTL 2
jstl ? 0
JSTL: getting a map's keys 19
JSTL Question 10
JSTL database access 0
JSTL in JEE 2.5 2
Struts - Getter method 6

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top