creating new object D2W

4 views
Skip to first unread message

Theodore Petrosky

unread,
Mar 29, 2012, 4:48:25 PM3/29/12
to webobje...@lists.apple.com
I am creating an new object page with this.

public EditPageInterface createBriefAction() {

    EditPageInterface component = D2W.factory().editPageForNewObjectWithConfigurationNamed("CreateBrief", session());
    component.setNextPage(session().context().page());

    if(component instanceof D2WPage) {
        D2WPage page = (D2WPage)component;
        page.d2wContext().takeValueForKey("Brief.CreateBrief", "navigationState");
    }
    return component;
}

I want to pass in a date to the object. is this the 'correct' or mostest correct way:

((D2WComponent) component).object().takeValueForKey( (new NSTimestamp()), "creationDate");

Ted

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (Webobje...@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/webobjects-dev-garchive-31333%40googlegroups.com

This email sent to webobjects-dev...@googlegroups.com

Ramsey Gurley

unread,
Mar 29, 2012, 5:16:23 PM3/29/12
to Theodore Petrosky, webobje...@lists.apple.com

On Mar 29, 2012, at 1:48 PM, Theodore Petrosky wrote:

> I am creating an new object page with this.
>
> public EditPageInterface createBriefAction() {
>
> EditPageInterface component = D2W.factory().editPageForNewObjectWithConfigurationNamed("CreateBrief", session());
> component.setNextPage(session().context().page());
>
> if(component instanceof D2WPage) {
> D2WPage page = (D2WPage)component;
> page.d2wContext().takeValueForKey("Brief.CreateBrief", "navigationState");
> }
> return component;
> }
>
> I want to pass in a date to the object. is this the 'correct' or mostest correct way:
>
> ((D2WComponent) component).object().takeValueForKey( (new NSTimestamp()), "creationDate");
>
> Ted


Sounds like model logic. Do it in the model. If you just want to set a create date, then use your EO's init() method.

public class Brief extends _Brief {

public void init(EOEditingContext ec) {
super.init(ec);
setCreationDate(new NSTimestamp());
}

}

And if code is just too cumbersome, you can do it in the userInfo dictionary of Brief inside your model :-)

Screen shot 2012-03-29 at 2.10.43 PM.png

David Holt

unread,
Mar 29, 2012, 5:36:50 PM3/29/12
to Ramsey Gurley, webobje...@lists.apple.com, Theodore Petrosky

> <Screen shot 2012-03-29 at 2.10.43 PM.png>
>
> You can read more about it here
>
> http://webobjects.mdimension.com/hudson/job/Wonder/javadoc/er/extensions/eof/ERXEntityClassDescription.html

How have I never seen this before?? Good grief, Wonder is huge and magical.

D

>
> Just do it in init() unless you want to use vanilla EOGenericRecords for some reason.
>
> Ramsey


>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list (Webobje...@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:

> https://lists.apple.com/mailman/options/webobjects-dev/programmingosx%40mac.com
>
> This email sent to program...@mac.com

Theodore Petrosky

unread,
Mar 29, 2012, 7:29:38 PM3/29/12
to Ramsey Gurley, webobje...@lists.apple.com
yes but I have other values like depending on who is logged in. the object is 'owned' by that user. I am storing the user in the session so i was thinking of:

((D2WComponent) component).object().takeValueForKey(session.currentUser, "person");

init sounds good for the creationDate but what about this 'user'.

Ted

--- On Thu, 3/29/12, Ramsey Gurley <rgu...@smarthealth.com> wrote:

> Just do it in init() unless you want to use vanilla
> EOGenericRecords for some reason.
>
> Ramsey
>
>

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (Webobje...@lists.apple.com)
Help/Unsubscribe/Update your Subscription:

David Holt

unread,
Mar 29, 2012, 7:37:40 PM3/29/12
to Theodore Petrosky, webobje...@lists.apple.com
See my note to Paul for an example of this.

Use ERXThreadStorage

David

_______________________________________________

Ramsey Gurley

unread,
Mar 29, 2012, 8:24:20 PM3/29/12
to David Holt, webobje...@lists.apple.com, Theodore Petrosky
You can very easily do it just the way you said originally Ted. That's actually the recommended way for Controller code. Model code, like setting a create date, should live in the model. Model View Controller. MVC. Keep a clean separation between these three and you will be able to reuse your existing work in new apps more easily.

David's recommendation is good too, but I would consider it more advanced usage. You have to be careful not to tie your model too tightly to your app if you start using thread storage. Too much thread storage can lead to mixed up MVC. You can find yourself with frameworks that only work with one app if you overuse it and start putting Controller code in your model.

The trick is knowing when it's controller code, and when it's model code. That comes with experience*.

Ramsey


*Experience - Something you get just after you needed it. ;-)

Reply all
Reply to author
Forward
0 new messages