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.

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();
}

Pierre

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 protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/webobjects- lists%40houdah.com

This email sent to [EMAIL PROTECTED]

- - -
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 protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to