Re: DirectAction: NSDictionary of the form values
Re: DirectAction: NSDictionary of the form values
- Subject: Re: DirectAction: NSDictionary of the form values
- From: David LeBer <email@hidden>
- Date: Thu, 5 Jul 2007 09:36:39 -0400
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
_______________________________________________
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