Re: EO/Java class default Values
Re: EO/Java class default Values
- Subject: Re: EO/Java class default Values
- From: Zak Burke <email@hidden>
- Date: Wed, 27 Sep 2006 16:49:26 -0400
Tarun Reddy wrote on 9/27/06 4:18 PM:
> I assume that awakeFromInsertion (based on the name) does not execute
> until the actual insertion of the object in the database, which means I
> can't rely on the value until the object has been saved. I am currently
> using the method to store creation date info, but I was hoping to get an
> initial value in before being saved to the database.
>
> (Trying to generalize the EditIdea form for both existing objects that
> I'm editing, and newly created objects. Since the status field is
> effectively a selector of sorts, I would like to have it always
> populated, even before being saved to the database, for business logic
> checks.)
This has been an interesting sort-of Best Practices thread to follow.
I dunno if this is good or bad, but I always use static constructors for
my EOs and I just do initialization there. I have code in my
EOEditingContext subclass that sets date-created and date-updated fields
in saveChanges(). This keeps the EO constructors clean but still lets me
set default values. For example:
public static SomeEO(EOEditingContext ec)
{
SomeEO eo = new SomeEO();
eo.insertObject(eo);
eo.setDefaultString("foo");
// ...
return eo;
}
The first two lines could be replaced by createAndInsertInstance(). This
is just the pattern I fell into before I knew about that method.
Hopefully, somebody will correct me if this is a terrible pattern.
Sadly, it wouldn't be the first time.
zak.
_______________________________________________
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