• 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: Mark Morris <email@hidden>
  • Date: Wed, 25 Oct 2006 13:27:26 -0500

Mike,

When a WOForm is submitted, the values in the form are pushed into your application using the value bindings you specified. If you bind a variable, it's clear that the variable value is set. However, you don't have to bind variables, you can also bind methods. In the case below, if you bind "itemSelected" to "checked", when the page is displayed WO will get the value from the itemSelected() method, and when the form is submitted WO will set the value using the setItemSelected( boolean ) method. You don't have to do anything but observe the naming convention.

Also, to add my 2 cents, Jerry's approach is the one I use. That approach in general lets you map between what's in the data and what's presented to the user, whether it's a checkbox or any other form item, to let you use what makes sense on each side without compromising either. (Did that make sense...?)

Regards,
Mark

On Oct 25, 2006, at 12:41 PM, Chip Myers wrote:

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: WORepetition, checked attribute question
      • From: Chip Myers <email@hidden>
References: 
 >Re: WORepetition, checked attribute question (From: Chip Myers <email@hidden>)

  • Prev by Date: Re: WORepetition, checked attribute question
  • Next by Date: Loading images in WO application
  • Previous by thread: Re: WORepetition, checked attribute question
  • Next by thread: Re: WORepetition, checked attribute question
  • Index(es):
    • Date
    • Thread