Re: Simple Question about bindings
Re: Simple Question about bindings
- Subject: Re: Simple Question about bindings
- From: Chuck Hill <email@hidden>
- Date: Wed, 26 Aug 2009 11:02:26 -0700
I am not sure what the problem is, but it is very unusual (and
probably just wrong) to sub-class NSArray etc. I think you want this:
privateNSMutableArray<CartItem> cart;
The add and cartTotal methods belong in the TemporaryOrder class.
Chuck
On Aug 26, 2009, at 10:20 AM, Francesco Romano wrote:
Hi..
This is a very simple question, and I was able to find a
workaround.. but I'd like to know where is the problem...
I've this class:
public class OrderComponent extends ERXComponent {
private TemporaryOrder order;
public OrderComponent(WOContext context) {
super(context);
}
public void setOrder(TemporaryOrder order) {
this.order = order;
}
public TemporaryOrder order() {
return order;
}
@Override
public void awake() {
super.awake();
setOrder(null);
}
}
All my order classes inherit from that class. (this only to have the
order object without rewriting it every time..).
If I have this binding:
CartSubtotal: WOString {
value = order.cart.cartTotal;
numberformat = "$#0.00";
}
When I render the page I get this exception:
valueForKey(): lookup of unknown key: 'cartTotal'. This class does
not have an instance variable of the name cartTotal or _cartTotal,
nor a method of the name cartTotal, _cartTotal, getCartTotal, or
_getCartTotal' object
'com.portonapoleone.store.utils.CartItem@eac903' key 'cartTotal'>
If I change the binding to this I have no problem:
CartSubtotal: WOString {
value = cartTotal;
numberformat = "$#0.00";
}
public double cartTotal() {
return order().cart().cartTotal();
}
These are the other classes involved:
public class TemporaryOrder {
private CartArray cart;
private String shipmentAddress;
public TemporaryOrder(CartArray c) {
cart = c;
}
public CartArray cart() {
return cart;
}
public void setShipmentAddress(String shipmentAddress) {
this.shipmentAddress = shipmentAddress;
}
public String shipmentAddress() {
return shipmentAddress;
}
}
public class CartArray extends NSMutableArray<CartItem> {
public boolean add(Prodotto p) {
return add(p,1);
}
public boolean add(Prodotto p, int i) {
CartItem ci = new CartItem(p);
if (contains(ci)) {
CartItem oldCI = objectAtIndex(indexOf(ci));
oldCI.quantity += i;
return true;
}
else {
ci.quantity = i;
return super.add(ci);
}
}
public double cartTotal() {
double total = 0;
Iterator<CartItem> it = this.iterator();
CartItem ci = null;
while (it.hasNext()) {
ci = it.next();
total += ci.totalPrice();
}
return total;
}
}
Francesco
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
--
Chuck Hill Senior Consultant / VP Development
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden