Re: newbie q: multiple fields insertion?
Re: newbie q: multiple fields insertion?
- Subject: Re: newbie q: multiple fields insertion?
- From: David LeBer <email@hidden>
- Date: Thu, 24 Nov 2005 12:09:19 -0500
On 24-Nov-05, at 11:37 AM, Jeremy Matthews wrote:
Following this example is easy:
public WOComponent createBlogEntryAction()
{
EOEditingContext ec = session().defaultEditingContext();
EOEnterpriseObject newEntry = EOUtilities.createAndInsertInstance
(ec, "BlogEntry");
newEntry.takeValueForKey(title, "title");
newEntry.takeValueForKey(body, "body");
newTitle = newBody = null;
ec.saveChanges();
return null;
}
However, I don't want to create a dozen single keys in WOBuilder,
and I'd rather create a key that references the Entity, so I can
easily drag its attributes to the correct fields. So, I created a
new key "newEntry" and made it of type "BlogEntry" (which is the
entity that includes title and body), instead of a bunch of
independent strings. This creation showed a key with references to
all the attributes in that entity.
However, I'm a bit confused as to how to replace these lines:
newEntry.takeValueForKey(title, "title");
newEntry.takeValueForKey(body, "body");
Since it no longer works, as those references now point to:
newEntry.title
newEntry.body
I've tried replacing title for newEntry.title (and the body
attribute as well), but it doesn't work.
What does?
OK...
The action above creates a new BlogEntry with the assumption that you
already have the values you need (captured from the form and stored
in local Strings).
You can turn that around:
Create the BlogEntry, insert it into an EditingContext and hand it to
a page that has the form.
Bind the form to the BlogEntry attributes (blogEntry.title,
blogEntry.body, etc)
Save the EC on form submit.
ie:
//In BlogListPage:
public EOEditingContext ec() {
return EOEditingContext ec = session().defaultEditingContext();
}
public WOComponent createBlogEntry() {
BlogEntryEditPage nextPage = (BlogEntryEditPage)pageWithName
("BlogEntryEditPage");
BlogEntry newEntry = (BlogEntry)EOUtilities.createAndInsertInstance
(ec(), "BlogEntry");
nextPage.setBlogEntry(newEntry);
nextPage.setBackPage(this.context().page());
return nextPage;
}
//In BlogEntryEditPage
protected BlogEntry _blogEntry;
protected WOComponent _backPage;
//accessors
public BlogEntry blogEntry() {
return _blogEntry;
}
public void setBlogEntry(BlogEntry newEntry) {
_blogEntry = newEntry;
}
public WOComponent backPage() {
return _backPage;
}
public void setBackPage(WOComponent page) {
_backPage = page;
}
// utility
public EOEditingContext ec() {
return EOEditingContext ec = session().defaultEditingContext();
}
// meat
public WOComponent saveChanges() {
ec().saveChanges();
return backPage();
}
This scenario would also work well if you are staying on the same
page but just toggling the visibility of an edit form hidden with
conditionals (setting an editFlag boolean).
If that doesn't work with your UI, you can look at other options but
things get a little more complex (creating new ECs to allow for user
discards, or using dummy value dictionaries). Let me know if that
makes sense.
--
;david
--
David LeBer
Codeferous Software
'co-defer-ous' adj. producing or containing code
site: http://www.codeferous.com
blog: http://david.codeferous.com
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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