Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

JSTL - iterating through lists (thanks Giblet) :)

  • 14-11-2007 05:09PM
    #1
    Registered Users, Registered Users 2 Posts: 1,127 ✭✭✭


    Im having trouble with lists in JSTL. I've created a rudimentary ordering system with a class hierarchy to suit. A sample hierarchy would be


    Order.class
    |- CustomerDetails.class
    |- PersonalDetails.class
    |-AddressList.class
    |- Address.class
    |- DeliveryAddress.class (sub-class of Address)
    |- BillingAddress.class (sub-class of Address)
    ... etc

    I've created a very simple OrderList class which just extends List (or ArrayList?). Now here's my problem. So I've created a jsp page to print out all orders from the database, Im using JDBC, with JSTL.
    <jsp:useBean id="admin" class="admin.AdminBean" scope="request" />
    

    AdminBean looks like this (just some helper utilities):
    public class AdminBean implements Serializable {
        
        private List orderList;
        
       /** Creates a new instance of AdminBean */
        public AdminBean() {
               this.orderList = getAllOrders();
        }
        
        public List getAllOrders(){
            return new ResultSets().getAllOrders();
        }
        
        public Order getOrder(int id){
            return new ResultSets().getOrder(id);
        }
    }
    

    So you would think that by doing:
    <c:forEach items="${admin.orderList}" var="order">
    </c:forEach>
    

    I could access the elements of this list (objects of class Order), and display the properties of them .

    But, I cant :(

    any thoughts? Do I need to use a ListIterator class?


Comments

  • Registered Users, Registered Users 2 Posts: 6,240 ✭✭✭hussey


    I'm surprised it has not thrown an error around 'admin.orderList"

    what this is saying is that using http://java.sun.com/j2se/1.4.2/docs/api/java/beans/Introspector.html

    it looks for a method called 'getOrderList'

    you have getAllOrders() .. so rename this or use
    <c:forEach items="${admin.allOrders}" var="order">


  • Registered Users, Registered Users 2 Posts: 12,026 ✭✭✭✭Giblet


    Grr :)

    Yeah you should be using it like this

    type varName

    public type getVarName()
    {
    return type;
    }

    in your class.


  • Registered Users, Registered Users 2 Posts: 1,127 ✭✭✭smcelhinney


    Im officially a dufus :rolleyes:

    thank you all..


Advertisement