Re: DirectAction: NSDictionary of the form values
Re: DirectAction: NSDictionary of the form values
- Subject: Re: DirectAction: NSDictionary of the form values
- From: "Jerry W. Walker" <email@hidden>
- Date: Thu, 5 Jul 2007 11:36:59 -0400
Hi, David,
On Jul 5, 2007, at 9:36 AM, David LeBer wrote:
On 5-Jul-07, at 9:26 AM, Jerry W. Walker wrote:
Hi, Edgar,
The NSDictionary that you receive from request().formValues()
contains NSArray values for each key. WO must presume that the
values returned are arrays of values, because some form elements
can return an array of values and WO has no way of determining
whether a given form value should be an array or not, so it opts
for the more general case, presuming that they should all be
arrays, and returns single valued arrays for the cases that only a
single value is returned for a given key.
Given that information, you could use request().formValueKeys() to
get the list of keys present and iterate through all the keys
using request().formValueForKey(key) to unwrap the array around
each given value to build out your own NSMutableDictionary to pass
to the EOUtilities.objectsMatchingValues method. Such as:
...
NSArray myResults = EOUtilities.objectsMatchingValues
(unwrappedFormValues());
...
private NSDictionary unwrappedFormValues()
{
NSArray keys = request().formValueKeys();
NSMutableDictionary results = new NSMutableDictionary(keys.count());
Enumeration e = keys.objectEnumerator();
while (e.hasMoreElements()) {
NSArray theValueArray = request().formValueForKey(key);
results.setObjectForKey(theValueArray.lastObject(), key);
}
return results.immutableClone();
}
Umm, request().formValueForKey("thekey"); should return a single
value. Calling valueForKey on the dictionary or formValuesForKey on
the request will return an array.
--
;david
--
David LeBer
Codeferous Software
'co-def-er-ous' adj. Literally 'code-bearing'
site: http://codeferous.com
blog: http://davidleber.net
profile: http://www.linkedin.com/in/davidleber
--
Toronto Area Cocoa / WebObjects developers group:
http://tacow.org
Yup, you're right.
I wrote the routine quickly this morning knowing that fact, but I had
so focused on why WO returns arrays for each of the values, that I
automatically and erroneously extracted the value from the
nonexistent array. Since I wrote the routine with Mail.app as my
editor, it didn't catch that. :-)
More coffee!
Regards,
Jerry
--
__ Jerry W. Walker,
WebObjects Developer/Instructor for High Performance Industrial
Strength Internet Enabled Systems
email@hidden
203 278-4085 office
_______________________________________________
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