Re: EO/Java class default Values
Re: EO/Java class default Values
- Subject: Re: EO/Java class default Values
- From: Tarun Reddy <email@hidden>
- Date: Wed, 27 Sep 2006 14:18:52 -0600
Hmm... I guess I knew that. I switched to using createAndInsertInstance
everywhere for that reason. I didn't see far enough that behind the
scenes it is doing a new Idea() and then adding it to the context. Of
course by the time it does the insert, the value is set in the
constructor.
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.)
Thanks, thought I was going crazy. Good (??) to know I'm not...
Tarun
On Wed, 2006-09-27 at 07:27 -0400, David LeBer wrote:
> On 27-Sep-06, at 6:39 AM, Ken Anderson wrote:
>
> > Exactly. You should always set default values through the
> > implementation of awakeFromInsertion(), like this:
> >
> > public void awakeFromInsertion(EOEditingContext ec) {
> > super.awakeFromInsertion(ec);
> > this.setSomething(aValue);
> > }
> >
> > Ken
> >
> > On Sep 27, 2006, at 3:07 AM, Markus Ruggiero wrote:
> >
> >> I can only think that the creation and insertion of the EO into
> >> the editing context does this. However I would not use the
> >> constructor to init any default value but implement the dedicated
> >> method awakeFromInsertion() for this purpose. The constructor is
> >> also executed when you read the object data from the database and
> >> the framework re-constructs your EO. This is probably not what you
> >> want.
>
> What Ken and Markus said!
>
> Joshua's book is very good, but I took it to task for this very thing
> here:
>
> <http://david.codeferous.com/?p=198>
>
>
> --
> ;david
>
> --
> David LeBer
> Codeferous Software
> 'co-def-er-ous' adj. Literally 'code-bearing'
> site: http://www.codeferous.com
> blog: http://david.codeferous.com
> --
> Toronto Area Cocoa / WebObjects developers group:
> http://www.tacow.org
>
>
_______________________________________________
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