Re: OT : Coding Standards (was New WebObjects 15 Minute Tutorial in Quicktime)
Re: OT : Coding Standards (was New WebObjects 15 Minute Tutorial in Quicktime)
- Subject: Re: OT : Coding Standards (was New WebObjects 15 Minute Tutorial in Quicktime)
- From: Anjo Krank <email@hidden>
- Date: Mon, 29 Mar 2004 09:06:35 +0200
- Xx-reply-to: email@hidden
Hi Jonathan,
Am 29.03.2004 um 06:50 schrieb Jonathan 'Wolf' Rentzsch:
Unless Im miss-understanding you, I normally do that sort of thing in
awakeFromInsertion() inside the Java class for the Entity. But its all
pretty class specific, How do you get a generic framework to do it ?
Either in the EOF layer (probably via a delegate, I think Wonder has
something which does this)
Yes: the ERXEntityClassDescription checks for the key "ERXDefaults" in
the attributes/relationship userInfo. From the JavaDoc:
Additionally, this class adds a concept of "Default" values that get
pushed into the object at creation time.
Simply add a "ERXDefaultValues" key into the entity's userInfo
dictionary that contains key-value-pairs for every default you want to
set. Alternately, you can set a "default" key on each of the
relationship or attrbute's userInfo<br />
Example:
"ERXDefaultValues" = {
// Example for simple values.
isAdmin = N;
isEditor = Y;
// Example for a related object (->Languages(pk,displayName)). You
need to enter the primary key value.
language = "de";
// Example for an NSArray of related objects
recommendingUser = "@threadStorage.actor";
// Example for an NSArray
articlesToRevisit = "@threadStorage.actor.articles";
// Example for a NSTimestamp. All static methods from
ERXTimestampUtilities are supported.
created = "@now";
updatePassword = "@tomorrow";
}
/JavaDoc
@threadStorage is the thread-level storage which is populated mainly in
session().awake() and sets things like the current user or whatever.
The naming could be better partitioned, and it could be enhanced to
read values off classes, but otherwise it works fine.
or if you're targeting DirectToWeb, by
subclassing D2W. Here's some slightly outdated code,
DefaultPropertyValueD2W, which populates new EOs based on the app's
rules:
<http://www.omnigroup.com/mailman/archive/webobjects-dev/2002-April/
022720.
html>
Yeah, I wonder why we didn't grab it like all the other goodies that
pop up on the lists:) We could factor out the code from
ERXEntityClassDescription and make the D2W part use it...
The EOF implementation is more generally applicable, but you'd have to
violate framework layering if you want to populate values from say,
your
WOSession, which is a common desire.
Which is what @threadStorage.session.someKey will do. The neat thing is
that you don't really ned a WOSession - only a value that is put into
ERXThreadStorage as "session". So you can also use it from long running
threads and stuff.
Arturo also mention Gap generation. What is it ?
<http://www.research.ibm.com/designpatterns/pubs/gg.html>
Which is what I prefer, as it actually spares me the mental labor to
decide if a class should be coded or not. Also, when you use the
"Clazz" pattern I outlined some time ago, then you will also want
type-safe fetch specs and a place to put them. So even when you EOs
don't have custom code (Mr/Ms/Miss) you probably want sth like
objectsByTitle(ec, "Ms") and you need to put that *somewhere*, don't
you?
Cheers, Anjo
_______________________________________________
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.