D2J: trying to totalize fields from detail in master EOGenericRecord
D2J: trying to totalize fields from detail in master EOGenericRecord
- Subject: D2J: trying to totalize fields from detail in master EOGenericRecord
- From: Johan Henselmans <email@hidden>
- Date: Fri, 16 Apr 2004 10:05:19 +0200
Hi,
I am building an administrative application, with lots of master/detail
forms in D2J. In some of them I totalize the amounts in de detail so
the user can see if he has filed in all the values correct. An example
is a EOGenericRecord Bankbook with an NSArray of bankbookdetails.
I am having trouble to define where the totalisation values should be
filled in while creating and changing these objects.
I first thought to do it in AwakeFromInsertion, but apparently the
array of bankbookdetails is not filled in yet, so the values are not
correct. I did get the array to totalize when I added the totalize
method to the insertion method of a new bankbookdetail (without the
values that still have to be filled in, that is).
Which procedure would you use in such a situation, or do you know
where to add the totalisation method, so it is called upon creation,
insertion and deletion of the NSArray of bankbookdetails?
Following is the relevant part of the source code:
public class Bankbook extends EOGenericRecord {
double bankbookTempAdd = 0;
double bankbookTempDeduct = 0;
public Bankbook() {
super();
}
public NSArray bankbookdetails() {
return (NSArray)storedValueForKey("bankbookdetails");
}
public void setBankbookdetails(NSArray value) {
takeStoredValueForKey(value, "bankbookdetails");
// setBankbookTemp();
}
public void addToBankbookdetails(EOGenericRecord object) {
setBankbookTemp();
includeObjectIntoPropertyWithKey(object, "bankbookdetails");
}
public void removeFromBankbookdetails(EOGenericRecord object) {
excludeObjectFromPropertyWithKey(object, "bankbookdetails");
setBankbookTemp();
}
public BigDecimal bankbookTempAdded() {
if ( bankbookTempAdd != 0){
return new BigDecimal(bankbookTempAdd);
} else {
return new BigDecimal("1");
}
}
public BigDecimal bankbookTempDeducted() {
if ( bankbookTempDeduct != 0 ){
return new BigDecimal(bankbookTempDeduct);
} else {
return new BigDecimal("1");
}
}
public void setBankbookTemp() {
bankbookTempAdd = 0;
bankbookTempDeduct = 0;
java.util.Enumeration e = bankbookdetails().objectEnumerator();
while (e.hasMoreElements()){
EOGenericRecord bankbookdettemp =
(EOGenericRecord)e.nextElement();
if (
((Boolean)bankbookdettemp.valueForKey("bankbookdetAdd")).equals( new
Boolean(false) ) ){
bankbookTempDeduct+=
((Number)bankbookdettemp.valueForKey("bankbookdetAmount")).doubleValue()
;
} else {
bankbookTempAdd+=
((Number)bankbookdettemp.valueForKey("bankbookdetAmount")).doubleValue()
;
}
}
}
-johan
Johan Henselmans
http://www.netsense.nl
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.