You could try something like this.

public class Cart extends ActionForm {
        
        private String subTotal;
        private ArrayList items;

public BigDecimal getSubTotal() {

                for(int i = 0;i < items.size();i++) {
                        CartItem item = (CartItem) items.get(i);
                        BigDecimal price = item.getPrice();
                        subTotal.add(price);
                }
                return subTotal;
        }
        
        public ArrayList getItems() {
                return items;
        }

        public void setItems(ArrayList items) {
                this.items = items;
        }

        public void setItem(CartItem item) {
                this.items.add(item);
        }

        public CartItem getItem(int i) {
                CartItem item = (CartItem)  items.get(i);
                return item;
        }

}
//
public class CartItem {
        private BigDecimal price;

        public BigDecimal getPrice() {
                return price;
        }

        public void setPrice(BigDecimal price) {
                this.price = price;
        }
}

Will also work with Double and even BigDecimal although BigDecimal can cause issues with BeanUtils, but string always works. Just means messing around doing the math and setting the value.

Cheers Mark


On 27 Dec 2003, at 16:23, Michael Marrotte wrote:


Kris,

Sounds good. Looks like the answer was (wasn't) looking for.

But, I'm sure it's a great feature in a different context.

Thanks,

--Mike M.

-----Original Message-----
From: Kris Schneider [mailto:[EMAIL PROTECTED]
Sent: Saturday, December 27, 2003 10:13 AM
To: Struts Users Mailing List
Subject: Re: <bean:write> not writing?


I'm pretty sure this boils down to the way PropertyUtils works. <bean:write> will use PropertyUtils.getProperty(bean, property) to retrieve the "subTotal" property from the bean "cart". PropertyUtils will test whether or not "cart" is a Map (which it is) and then call Map.get to retrieve the property value. Since you've defined "subTotal" as a standard JavaBean property, <bean:write> (or really PropertyUtils) won't be able to find it.

Michael Marrotte wrote:

Here's the bean:

public class Cart extends HashMap {
    private double subTotal = 400.00;
    public double getSubTotal(){return subTotal;}
}


Here's the Java:


session.setAttribute("cart", new Cart());


Here's the JSP


<bean:write name="cart" property="subTotal"/> // no output?
<%= ((csp.Cart)session.getAttribute("cart")).getSubTotal() %> // works,
writes 400.0



Here's the problem


<bean:write> isn't producing any output, but

<%= ... %> is...

Any ideas are greatly appreciated.

Thanks,

--Mike M.

-- Kris Schneider <mailto:[EMAIL PROTECTED]> D.O.Tech <http://www.dotech.com/>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to