Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WORepetition, checked attribute question



Hi Jerry:

I'm having trouble understanding how to call the method that you defined, setItemSelected().  Does this somehow occur once the page is submitted?  Or do I need to call this method from an onClick attribute?

Thanks for your help so far!

-Mike




=======================================
public NSArray itemList;
public Item currentItem;
public NSMutableArray selectionList;

// Presume that itemList and selectionLists have been initialized.

public boolean itemSelected()
{
return selectionList.containsObject(currentItem);
}

public void setItemSelected(boolean value)
{
// is the Item already on the selection list?
boolean oldValue = itemSelected();

        // if selected, and not already on the list, add
 it
if (value && !oldValue)
selectionList.addObject(currentItem);

        // if not selected but already on list, remove it
else if (!value && oldValue)
selectionList.removeObject(currentItem);

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

For the WORepetition, bind the currentItem to the "item" binding, bind the itemList to the "list" binding.

For the iterated WOCheckBox, bind itemSelected to the "checked" binding. This, of course, binds to the two accessor methods for which there is no instance variable. The get accessor simply checks to see whether the item is in the selected list. The set accessor deals with the four cases:

is
 checked    on selection list      action
true true do nothing
true false add to list
false true remove from list
false false do nothing

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:
http://lists.apple.com/mailman/options/webobjects-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.