Re: Simple Question about bindings
Re: Simple Question about bindings
- Subject: Re: Simple Question about bindings
- From: Michael Shkutkov <email@hidden>
- Date: Wed, 26 Aug 2009 22:48:48 +0400
I guess, the cause of this problem is the fact that NSArray implements NSKeyValueCoding interface and has valueForKey method.
Obviously extending NSMutableArray is really bad idea...
On Wed, Aug 26, 2009 at 9:20 PM, Francesco Romano
<email@hidden> 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;
}
}
_______________________________________________
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
--
Cheers, Michael
_______________________________________________
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