• 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: newbie q: multiple fields insertion?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: newbie q: multiple fields insertion?


  • Subject: Re: newbie q: multiple fields insertion?
  • From: Lachlan Deck <email@hidden>
  • Date: Fri, 25 Nov 2005 12:11:20 +1100

Hi there,

On 25/11/2005, at 4:09 AM, David LeBer wrote:

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:
<...>
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.

To further enhance David's example (and provide for user discards - if they choose not to save) see below. The advantage of using a child editing context in this scenario is that if the user chooses to not save changes then you're not left with a newly inserted, but not populated, object in the default editing context so that your logic of (ec.hasChanges()) doesn't come unstuck.


Note that if any of your fields are relationships to other entities (e.g., a toOne via a popup selection) then you'll need some extra logic in your entity class (but that's for another time).

<...>
//In BlogListPage:

public WOComponent editBlogEntry() { BlogEntryEditPage nextPage;

	nextPage = createBlogEntry();
	nextPage.takeValueForKey( aBlogEntry, "blogEntry" );
	return nextPage;
}

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 EOEditingContext _ec = null;
protected BlogEntry _blogEntry = null;
protected WOComponent _backPage = null;

//accessors public BlogEntry blogEntry() {
if ( _blogEntry == null ) {
_blogEntry = (BlogEntry)EOUtilities.createAndInsertInstance( ec(), "BlogEntry" );
}
	return _blogEntry;
}

public void setBlogEntry(BlogEntry newEntry) {
_blogEntry = (BlogEntry)EOUtilities.localInstanceOfObject( ec(), newEntry );
}

public WOComponent backPage() {
	return _backPage;
}

public void setBackPage(WOComponent page) {
	_backPage = page;
}

// utility
public EOEditingContext ec() {
	if ( _ec == null ) {
		// we use a child ec here to allow for discards
		_ec = new EOEditingContext(session().defaultEditingContext());
		_ec.setSharedEditingContext(null);
	}
	return _ec;

// we'll avoid using the default ec here so that if the edit is
// not saved, then the changes are automatically discarded.
// i.e., we don't leave a newly inserted BlogEntry that's not properly
//       populated in the main ec.
//
//	return EOEditingContext ec = session().defaultEditingContext();
}

// meat
public WOComponent saveChanges() {
	try {
		// push the changes back to papa
		ec().saveChanges();
	} catch (Exception e) {
		NSLog.err.appendln( e );
	}
	return backPage();
}

with regards, --

Lachlan Deck


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

References: 
 >newbie q: multiple fields insertion? (From: Jeremy Matthews <email@hidden>)
 >Re: newbie q: multiple fields insertion? (From: David LeBer <email@hidden>)

  • Prev by Date: Re: Trouble referring to an item in a WORepetition in Java code
  • Next by Date: Re: Trouble referring to an item in a WORepetition in Java code
  • Previous by thread: Re: newbie q: multiple fields insertion?
  • Next by thread: WODisplayGroup advice needed
  • Index(es):
    • Date
    • Thread