Re: NSDictionary and WOPopup Question
Re: NSDictionary and WOPopup Question
- Subject: Re: NSDictionary and WOPopup Question
- From: Hugi Thordarson <email@hidden>
- Date: Wed, 27 Oct 2004 18:58:06 +0000
Ok, I think I get this. At the very least, I'm going to make an
attempt. I'm going to write this out in code, since I'm afraid of
confusing you to the point of desperation if I attempt regular English
:-).
Working from the following assumptions:
* You have an NSDictionary called "divisions".
* It contains the names of divisions as keys, and their ID-numbers as
values (Integers).
* No two divisions have the same name
* You want to display the division names in a pop-up menu.
* The value you need is the Integer value
* You're setting an attribute called "divisionNumber" in an EO instance
called someEO
Of course, the best thing to do is to take all of this and put it in a
separate component.
(Disclaimer: I did not check to see if this code compiles and thus it
might contain errors.)
/**
* Your divisions and their numbers
*/
public NSDictionary divisions() {
NSMutableDictionary d = new NSMutableDictionary();
d.setObjectForKey( new Integer( 1 ), "Sales" );
d.setObjectForKey( new Integer( 2 ), "Human resources" );
d.setObjectForKey( new Integer( 3 ), "Alien resources" );
return d;
}
/**
* The names of your divisions.
* Bind this to your WOPopUpButton's "list" attribute
*/
public NSArray divisionNames() {
return divisions().allKeys();
}
/**
* Gets the correct display string from your dictionary for the WOPopUp
* Bind selectedDivisionName to your WOPopUpButton's
"selection"-attribute.
*/
public String selectedDivisionName() {
Enumeration e = divisions().objectEnumerator();
while( e.hasMoreElements() ) {
Object o = e.nextElement();
if( o.equals( someEO.divisionNumber() ) )
return (String)divisions().allKeysForObject( s ).lastObject();
}
return null;
}
/**
* Sets the selected division name.
*/
public void setSelectedDivisionName( String newDivisionName ) {
someEO.setDivisionNumber( (String)divisions().valueForKey(
newDivisionName ) );
}
/**
* Ends my letter ;-)
*/
public String greetings() {
return "Cheers,\nHugi";
}
// Hugi Thordarson
// Development mgr.
// Vefsyn hf. - development, analysis, marketing
// http://www.vefsyn.com/
On 27.10.2004, at 17:51, James Cicenia wrote:
OK - lol -
Say I have a dictionary of Integers with a string key for display.
I bind allKeys to the list. However how will I get the string when
the object gives a Integer back? Well I thought then let me
create a reverse dictionary with strings as the values and the
Integers as the key. Then in my selection methods I can one
dictionary to get the string and the other to set back the Integer.
Does any of this make sense?
- James
On Oct 27, 2004, at 12:13 PM, Chuck Hill wrote:
I, for one, can't understand what you mean. Can you say that again?
:-)
Chuck
On Oct 27, 2004, at 7:18 AM, James Cicenia wrote:
Hello -
I want to do a repeating list with a popup. I thought that
NSDictionary would be good, especially now that I look to use KVC
for everything. Anyway, my first popup with NSDictionary had me
making two NSDictionaries with the key/values just reversed. This
way I can get and set the popup using the two dictionaries in
reverse.
Is this the way you pros do it?
- James Cicenia
_______________________________________________
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