Sent from my iPad
On 2012-04-06, at 7:48 AM, David LeBer <[email protected]> wrote: > Um, it looks like David got a little confused. Copied code in an email. Recipe for disaster. > > You won't (and shouldn't) have access to the session in your EO. That is why > you need to use ERXThreadStorage. Yes! > > in Session awake and the setter for user, push it into ERXThreadStorage. i.e: > > ERXThreadStorage.takeValueForKey(user(), "currentUser"); > > In EO init: > > User user = ERXThreadStorage.valueForKey("currentUser"); > if (user != null) { > User localUser = user.localInstanceIn(ec); > // etc > } > > -- > David LeBer > Codeferous Software > > On 2012-04-06, at 10:22 AM, Theodore Petrosky wrote: > >> I tried that and I get an error that it doesn't know what session() is. >> >> The method session() is undefined for the type Brief >> >> I am thinking, my EOs are in a framework. >> >> How can I refer to the session if the EO doesn't know anything about the >> session? >> >> Ted >> >> >> >> --- On Fri, 4/6/12, David Holt <[email protected]> wrote: >> >>> From: David Holt <[email protected]> >>> Subject: Re: D2W creating a new object? >>> To: "Theodore Petrosky" <[email protected]> >>> Cc: "[email protected]" <[email protected]> >>> Date: Friday, April 6, 2012, 9:41 AM >>> Check the code for adding a person to >>> a Brief further down in my previous email. If you do it in >>> the EO class, you shouldn't have the problem. >>> >>> Sent from my iPad >>> >>> On 2012-04-06, at 4:31 AM, Theodore Petrosky <[email protected]> >>> wrote: >>> >>>> David, >>>> >>>> I tried this method and still the same issue. >>>> >>>> There is a relationship with a person (user). Without a >>> user added, I get the normal error that I need a user: >>>> >>>> Could not save your changes: A Brief must have a >>> Person. >>>> >>>> I added: >>>> >>>> Person thePerson = session().user().localInstanceIn( >>> ((D2WPage) nextPage).object().editingContext()); >>>> ((D2WComponent) nextPage).object().takeValueForKey( >>> thePerson, "person"); >>>> >>>> Thats when I get the infamous: >>>> >>>> Error: >>> java.lang.IllegalStateException: Adaptor >>> com.webobjects.jdbcadaptor.JDBCAdaptor@3cb088f8 failed to >>> provide new primary keys for entity 'Brief' >>>> Reason: Adaptor >>> com.webobjects.jdbcadaptor.JDBCAdaptor@3cb088f8 failed to >>> provide new primary keys for entity 'Brief' >>>> >>>> If it didn't like the person entity or the >>> editingContext, I assume I would get an error complaining >>> about that. >>>> >>>> This is D2W land and with all the magic going on, I >>> think I am out of Fairy dust. >>>> >>>> Ted >>>> >>>> >>>> >>>> >>>> --- On Thu, 4/5/12, David Holt <[email protected]> >>> wrote: >>>> >>>> | I use this method: >>>> | >>>> | | public WOComponent createPersonAction() { >>>> | | return >>> newObjectForEntityName(PERSON); >>>> | | } >>>> | >>>> | | public WOComponent >>> newObjectForEntityName(String entityName) { >>>> | | WOComponent nextPage = null; >>>> | | try { >>>> | | EditPageInterface epi = >>> D2W.factory().editPageForNewObjectWithEntityNamed(entityName, >>> session()); >>>> | | >>> epi.setNextPage(session().context().page()); >>>> | | nextPage = (WOComponent) epi; >>>> | | } >>>> | | catch (IllegalArgumentException e) { >>>> | | ErrorPageInterface epf = >>> D2W.factory().errorPage(session()); >>>> | | epf.setMessage(e.toString()); >>>> | | >>> epf.setNextPage(session().context().page()); >>>> | | nextPage = (WOComponent) epf; >>>> | | } >>>> | | return nextPage; >>>> | | } >>>> | >>>> | >>>> | On 2012-04-05, at 10:53 AM, Theodore Petrosky wrote: >>>> | >>>> | I am creating a new 'Brief' object in my D2W app like >>> 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"); >>>> | >>>> | This could be a rule: >>>> | 50 : pageConfiguration = 'CreateBrief' => >>> navigationState = "Brief.CreateBrief" >>> [com.webobjects.directtoweb.Assignment] >>>> | >>>> | >>> NSLog.out.appendln( ((D2WPage) >>> component).object().allPropertyKeys()); >>>> | >>>> | Person >>> thePerson = session().user().localInstanceIn(((D2WPage) >>> component).object().editingContext()); >>>> | >>>> | ((D2WComponent) >>> component).object().takeValueForKey( thePerson, "person"); >>>> | ((D2WComponent) >>> component).object().takeValueForKey( (new NSTimestamp()), >>> "creationDate");// (new NSTimestamp()); >>>> | >>>> | This code should be in your Brief eo init() method. >>> Something like: >>>> | >>>> | | public void init(EOEditingContext ec) { >>>> | | super.init(ec); >>>> | | Person thePerson = >>> session().user().localInstanceIn(ec); >>>> | | setPersonRelationship(thePerson); >>>> | | setCreationDate(new NSTimestamp()); >>>> | | } >>>> | >>>> | >>>> | | } >>>> | | return component; >>>> | } >>>> | >>>> | When I click the save button I am getting: >>>> | >>>> | >>>> | IllegalStateException: Adaptor >>> com.webobjects.jdbcadaptor.JDBCAdaptor@43c8308 failed to >>> provide new primary keys for entity 'Brief' >>>> | >>>> | >>>> | Am I supposed to do something more here? >>>> | >>>> | Ted public WOComponent createPersonAction() { >>>> | | return >>> newObjectForEntityName(PERSON); >>>> | | } >>>> | >>>> | | public WOComponent >>> newObjectForEntityName(String entityName) { >>>> | | WOComponent nextPage = null; >>>> | | try { >>>> | | EditPageInterface epi = >>> D2W.factory().editPageForNewObjectWithEntityNamed(entityName, >>> session()); >>>> | | >>> epi.setNextPage(session().context().page()); >>>> | | nextPage = (WOComponent) epi; >>>> | | } >>>> | | catch (IllegalArgumentException e) { >>>> | | ErrorPageInterface epf = >>> D2W.factory().errorPage(session()); >>>> | | epf.setMessage(e.toString()); >>>> | | >>> epf.setNextPage(session().context().page()); >>>> | | nextPage = (WOComponent) epf; >>>> | | } >>>> | | return nextPage; >>>> | | } >>>> | >>>> | >>>> | On 2012-04-05, at 10:53 AM, Theodore Petrosky wrote: >>>> | >>>> | I am creating a new 'Brief' object in my D2W app like >>> 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"); >>>> | >>>> | This could be a rule: >>>> | 50 : pageConfiguration = 'CreateBrief' => >>> navigationState = "Brief.CreateBrief" >>> [com.webobjects.directtoweb.Assignment] >>>> | >>>> | >>> NSLog.out.appendln( ((D2WPage) >>> component).object().allPropertyKeys()); >>>> | >>>> | Person >>> thePerson = session().user().localInstanceIn(((D2WPage) >>> component).object().editingContext()); >>>> | >>>> | ((D2WComponent) >>> component).object().takeValueForKey( thePerson, "person"); >>>> | ((D2WComponent) >>> component).object().takeValueForKey( (new NSTimestamp()), >>> "creationDate");// (new NSTimestamp()); >>>> | >>>> | This code should be in your Brief eo init() method. >>> Something like: >>>> | >>>> | | public void init(EOEditingContext ec) { >>>> | | super.init(ec); >>>> | | Person thePerson = >>> session().user().localInstanceIn(ec); >>>> | | setPersonRelationship(thePerson); >>>> | | setCreationDate(new NSTimestamp()); >>>> | | } >>>> | >>>> | >>>> | | } >>>> | | return component; >>>> | } >>>> | >>>> | When I click the save button I am getting: >>>> | >>>> | >>>> | IllegalStateException: Adaptor >>> com.webobjects.jdbcadaptor.JDBCAdaptor@43c8308 failed to >>> provide new primary keys for entity 'Brief' >>>> | >>>> | >>>> | Am I supposed to do something more here? >>>> | >>>> | Ted >>>> >>> >> >> _______________________________________________ >> Do not post admin requests to the list. They will be ignored. >> Webobjects-dev mailing list ([email protected]) >> Help/Unsubscribe/Update your Subscription: >> https://lists.apple.com/mailman/options/webobjects-dev/dleber_wodev%40codeferous.com >> >> This email sent to [email protected] > _______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to [email protected]
