• 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: WORepetition, checked attribute question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WORepetition, checked attribute question


  • Subject: Re: WORepetition, checked attribute question
  • From: Chuck Hill <email@hidden>
  • Date: Tue, 5 Dec 2006 11:43:53 -0800


On Dec 5, 2006, at 10:53 AM, Pierre Bernard wrote:

To make it even faster: do not return null from an action method. Return context().page() instead. You will be saving WebObjects the effort of propagation the action down element branches that come after your action.

That is good advice.


I'd also rather not rely on the object being in the default editing context. You might change your mind about that one day because the default editing context really is not the best place for modified objects. Thus:

EOEditingContext ec = this.user.editingContext();

ec.lock();

try {
	ec.saveChanges();
}
finally {
	ec.unlock();
}

That might be a bit dangerous advice. Doing this is good advice:

user.editingContext().saveChanges();

Locking like that is either useless (if the ec is already locked) or dangerous (if it is not locked). It is dangerous because it leads you to think that you are locking correctly when you are not. The EC needs to be locked during any and all access to the EOs in it, not just during fetches, saves, etc. ERXEC in Wonder and the MultiECLockManager both lock editing contexts at the start of the R-R loop and unlock them at the end. This is the best, and probably the only sure way, to ensure that the editing contexts are properly locked when they need to be.


Chuck



On 5 Dec 2006, at 19:30, David Holt wrote:

Hi Mark,

Oh man! All that code reduced to:

	NSMutableArray favourites;

	public ElementSearch(WOContext context) {
		super(context);
		favourites();
	}


/** @TypeInfo Element */ public NSMutableArray favourites() { if (favourites == null) { favourites = (NSMutableArray)user.favouriteElements(); } return favourites; }

    public boolean elementChecked()
    {
        return favourites.containsObject(anElement);
    }

public void setElementChecked(boolean newElementChecked) {

// Jerry Walker's code:
// is the element already in the favourites?
boolean oldValue = elementChecked();
// if selected, and not already in the favourites list, add it
if (newElementChecked && !oldValue) {
user.addObjectToBothSidesOfRelationshipWithKey(anElement, "favouriteElements");
}
// if not selected but already in the favourites list, remove it
else if ( !newArtifactChecked && oldValue) {
user.removeObjectFromBothSidesOfRelationshipWithKey(anElement, "favouriteElements");
}


	}

	public WOComponent submit()
	{
		Session session = (Session)session();
		EOEditingContext ec = session.defaultEditingContext();
		ec.saveChanges();
		return null;
	}


Where do I send the beer??

I didn't realize that I could cast the NSArray user.favouriteElements() to NSMutableArray. That was pretty much the key. NOW it's FAST!

Thanks so much,

David

--
It's like driving a car at night. You never see further than your headlights, but you can make the whole trip that way.


E. L. Doctorow

from Sunbeams: http://www.thesunmagazine.org


On 5 Dec 2006, at 9:41 AM, Mark Morris wrote:

you should be able to directly use user.favouriteElements() instead of going through selectionList. In other words, elementChecked and setElementChecked can directly work on userFavouriteElements().

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


This email sent to email@hidden

- - - Houdah Software s. à r. l. http://www.houdah.com - Quality Mac OS X software - Premium WebObjects consulting




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40global-village.net


This email sent to email@hidden

--

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects






_______________________________________________
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: WORepetition, checked attribute question (From: David Holt <email@hidden>)
 >Re: WORepetition, checked attribute question (From: Mark Morris <email@hidden>)
 >Re: WORepetition, checked attribute question (From: David Holt <email@hidden>)
 >Re: WORepetition, checked attribute question (From: Pierre Bernard <email@hidden>)

  • Prev by Date: How do I use JAVA Frame instead of WOFrame in my app
  • Next by Date: Re: How do I use JAVA Frame instead of WOFrame in my app
  • Previous by thread: Re: WORepetition, checked attribute question
  • Next by thread: WO Won't Launch
  • Index(es):
    • Date
    • Thread