• 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: Variable method name signature
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Variable method name signature


  • Subject: Re: Variable method name signature
  • From: Chuck Hill <email@hidden>
  • Date: Mon, 27 Apr 2009 11:00:50 -0700


On Apr 27, 2009, at 10:54 AM, David Holt wrote:

Thanks Chuck. That is very cool. And just to confirm, the setter would look like this?

/**
* @param email the email to set
*/
public void setEmail(String email) {
NSLog.out.appendln("AjaxModalCurrentAddressDetail setEmail to " +email);
((Address)aPerson().valueForKey(currentAddressType +"Address")).takeValueForKey(email, "email");

As you are casting to Address, no need for the takeValue:

((Address)aPerson().valueForKey(currentAddressType +"Address")).setEmail(email);

You might want to package the KVC look up like this:

public Address address() {
	return (Address)aPerson().valueForKey(currentAddressType+"Address");
}

That makes it easier / clearer to use:

address().setEmail(email);


Chuck


	}


On 27-Apr-09, at 10:40 AM, Chuck Hill wrote:


On Apr 27, 2009, at 10:38 AM, David Holt wrote:

Hello all,

I apologize in advance if this is an obvious question. I am calling a component to fill out an address form and I would like to make it generic for several different address types but I am not quite sure how. Is it possible to call different methods on an EO based on a string passed to the component? I am thinking something along the lines of the code below, but that doesn't work:



	private String email;
	private String currentAddressType;


public void setCurrentAddressType(String string) { // string takes values such as "home", "work" currentAddressType = string; }

	/**
	 * @return the email
	 */
	public String email() {
		return aPerson().+currentAddressType+"Address"().email();

KVC Magic:

return ((Address)aPerson().valueForKey(currentAddressType +"Address")).email();


Chuck


	}


/**
* @param email the email to set
*/
public void setEmail(String email) {
NSLog.out.appendln("AjaxModalCurrentAddressDetail setEmail to " +email);
aPerson().+currentAddressType+"Address"().setEmail(email);
}


Thanks!

David
_______________________________________________
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

-- Chuck Hill Senior Consultant / VP Development

Come to WOWODC'09 in San Fran this June!
http://www.wocommunity.org/wowodc09/



-- Chuck Hill Senior Consultant / VP Development

Come to WOWODC'09 in San Fran this June!
http://www.wocommunity.org/wowodc09/

_______________________________________________
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: 
 >Variable method name signature (From: David Holt <email@hidden>)
 >Re: Variable method name signature (From: Chuck Hill <email@hidden>)
 >Re: Variable method name signature (From: David Holt <email@hidden>)

  • Prev by Date: Re: Variable method name signature
  • Next by Date: Re: exception with a not null constraint....
  • Previous by thread: Re: Variable method name signature
  • Next by thread: [Reminder] WOWODC West topics and group discounts
  • Index(es):
    • Date
    • Thread