• 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: David Holt <email@hidden>
  • Date: Mon, 04 Dec 2006 14:16:24 -0800

Hi Jerry and list,

I have just implemented the code you provided below in a checkbox array and it has really sped up the response in my application compared to my previous implementation. Thanks!

The next step for me is to make the selectionList persistent in the database so that when the user comes back to the list they can see what elements have already been checked. I have a solution, but I am not sure if it is the most efficient possible. Would you all mind telling me if there is a more accepted way of doing this?

Thanks,

David

----

NSMutableArray mostRecentRemoval = new NSMutableArray();
NSMutableArray mostRecentAddition = new NSMutableArray();

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

/** @TypeInfo Element */
public NSMutableArray selectionList() {
if (selectionList == null) {
selectionList = new NSMutableArray(favourites.mutableClone());
} 
return selectionList;
}



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

public void setElementChecked(boolean newElementChecked) {

// Jerry Walker's code:
// is the Artifact already on the selection list?
boolean oldValue = elementChecked();
// if selected, and not already on the list, add it
if (newElementChecked && !oldValue) {
selectionList.addObject(anElement);
mostRecentAddition.addObject(anElement);
}

// if not selected but already on the list, remove it
else if ( !newArtifactChecked && oldValue) {
selectionList.removeObject(anElement);
mostRecentRemoval.addObject(anElement);
}

// if selected and already on the list, do nothing
// if not selected and not on the list, do nothing
}

    public WOComponent submit()
    {
Session session = (Session)session();
EOEditingContext ec = session.defaultEditingContext();
int y = 0;
while (mostRecentRemoval.count() != y) {
anElement = (Element)mostRecentRemoval.objectAtIndex(y);
user.removeObjectFromBothSidesOfRelationshipWithKey(anElement, "favouriteElements");
++y;
}
int z = 0;
// while (selectionList.count() != z) {
while (mostRecentAddition.count() != z) {
anElement = (Element)mostRecentAddition.objectAtIndex(z);
user.addObjectToBothSidesOfRelationshipWithKey(anElement, "favouriteElements");
++z;
}
ec.saveChanges(); 
return null;
}



On 24 Oct 2006, at 3:46 PM, Jerry W. Walker wrote:


Here's the explanation and the code for the idiom which cleverly avoids this side effect:

Presume that you have a list of Items, itemList, over which you want to iterate and associate a checkbox. Presume also that you want to capture the results, selectionList, of the user's checking some set of checkboxes when they submit the form:

That's it, simple, fast and elegant.

Regards,
Jerry


 _______________________________________________
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

  • Follow-Ups:
    • Re: WORepetition, checked attribute question
      • From: Mark Morris <email@hidden>
  • Prev by Date: Re: Disaster.. now why doesn't my app start. (James Cicenia)
  • Next by Date: Re: embedded frameworks + split install
  • Previous by thread: Re: Disaster.. now why doesn't my app start. (James Cicenia)
  • Next by thread: Re: WORepetition, checked attribute question
  • Index(es):
    • Date
    • Thread