can a WODisplayGroup use a subclass of an entity?
can a WODisplayGroup use a subclass of an entity?
- Subject: can a WODisplayGroup use a subclass of an entity?
- From: Denis Stanton <email@hidden>
- Date: Wed, 10 Sep 2003 11:30:21 +1200
I thought I had a good idea to clean up my code a bit, but it's not
working. Maybe the idea was flawed, or maybe I'm just missing a detail.
I have an entity (Holiday) that represents a holiday reservation.
There are a number of common operations I need to perform on instances
of this entity. For example, the table stores start and finish date
and I frequently need to calculate duration by subtracting one from the
other.
To do this I simply added a public int duration(){...} method to
Holiday.java. I have added a number of methods like this. My worry is
I am still developing the database and every time I extend the entity
definition I generate the java class again. I have to be very careful
to merge the generated code with my extended class. I'm worried that I
could slip up and lose my custom code. It finally dawned on me that I
was not making use of Java inheritance. Instead of adding methods to
Holiday.java I should define public class HolidayExt extends Holiday
{...} and add my custom code there. Then in my WOComponents I always
declare instance to be HolidayExt holidayItem = new HolidayExt()
Seems OK, until I get to my WODisplayGroup. This requires me to
specify and entity name, so I have to pick Holiday, not HolidayExt.
Then the WODisplayGroup controls a repetition, using each instance of
Holiday to set the value of the repetition item. The problem is that
this item is of class HolidayExt so I get a run time error:
"java.lang.IllegalArgumentException: While trying to set the field
"holidayItem" on an object of type HolidayList we expected a HolidayExt
but received a Holiday with a value of {...} This often happens if you
don't know what you're doing"
(paraphrased slightly - the message takes up two screen heights and
it's on another computer).
I looked up the displaygroup initialisation in the WOComponent's .woo
but it only specifies the entity name (Holiday) and doesn't offer a
place to name the class as HolidayExt
So is there a way around this?
I thought maybe I could write a method in the WoComponent that used the
WODisplayGroup.
public void setHolidayItem(Holiday newHoliday){
holidayItem = (HolidayExt)newHoliday;
}
but that gives a java.lang.ClassCastException: Holiday
Any comments?
Denis Stanton
email@hidden
Home: (09) 533 0391
mobile: 021 1433622
_______________________________________________
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.