JSTL - Conditional Logic in a getter

Discussion in 'Java' started by jc1771, Sep 9, 2003.

  1. jc1771

    jc1771 Guest

    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
     
    jc1771, Sep 9, 2003
    #1
    1. Advertising

  2. jc1771

    Mark Meyer Guest

    In our last episode, (jc1771) wrote:
    > isSorted == true;


    I think you mean

    isSorted = true;

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

    Mark Meyer
    Raytheon Voice (972)344-0830 Fax (972)344-6840
     
    Mark Meyer, Sep 9, 2003
    #2
    1. Advertising

  3. jc1771

    jc1771 Guest

    Mark Meyer <> wrote in message news:<>...
    > In our last episode, (jc1771) wrote:
    > > isSorted == true;

    >
    > I think you mean
    >
    > isSorted = true;
    >
    > I don't know if this fixes your problem, but it couldn't hurt.
    >
    > Mark Meyer
    > 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
     
    jc1771, Sep 10, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Mark Bram

    Custom JSTL that accepts JSTL expression

    Robert Mark Bram, Dec 15, 2004, in forum: Java
    Replies:
    0
    Views:
    1,007
    Robert Mark Bram
    Dec 15, 2004
  2. sibasish
    Replies:
    0
    Views:
    898
    sibasish
    Mar 21, 2006
  3. John
    Replies:
    4
    Views:
    955
    RedGrittyBrick
    Apr 1, 2008
  4. DaFoot
    Replies:
    1
    Views:
    1,760
    DaFoot
    Oct 23, 2008
  5. spike
    Replies:
    8
    Views:
    1,543
    Steve Holden
    Feb 9, 2010
Loading...

Share This Page