• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: D2W creating a new object?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: D2W creating a new object?


  • Subject: Re: D2W creating a new object?
  • From: David Holt <email@hidden>
  • Date: Fri, 06 Apr 2012 07:53:27 -0700

Hi Ted, 

ERXThreadStorage solves this problem. See my email from March 29 th in the D2W: Pattern for complex object creation thread. The code you need to create EOs is included.

BugTracker uses this pattern, as does SimpleBlog.

Sent from my iPad

On 2012-04-06, at 7:22 AM, Theodore Petrosky <email@hidden> 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@hidden> wrote:

From: David Holt <email@hidden>
Subject: Re: D2W creating a new object?
To: "Theodore Petrosky" <email@hidden>
Cc: "email@hidden" <email@hidden>
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@hidden>
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@hidden>
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@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: D2W creating a new object? (From: Theodore Petrosky <email@hidden>)

  • Prev by Date: Re: D2W creating a new object?
  • Next by Date: Re: D2W creating a new object?
  • Previous by thread: Re: D2W creating a new object?
  • Next by thread: debugging ERXMainRunner v Application
  • Index(es):
    • Date
    • Thread