• 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: DirectAction: NSDictionary of the form values
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: DirectAction: NSDictionary of the form values


  • Subject: Re: DirectAction: NSDictionary of the form values
  • From: "Edgar Ra. Klein" <email@hidden>
  • Date: Thu, 5 Jul 2007 15:54:16 +0200

Hi Jerry,

On 05.07.2007, at 15:26, 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.

This is a good thing to know, thank you!

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();
}

The code I just wrote is:

public NSDictionary convertFormValues() {
	NSMutableDictionary resultDictionary = new NSMutableDictionary();
	NSArray keys = request().formValueKeys();

	for (int i = 0 ; i < keys.count() ; i++) {
		String key = (String) keys.objectAtIndex(i);

		String value = (String) request().formValueForKey(key);

		resultDictionary.takeValueForKey(value, key);
	}

	return resultDictionary.immutableClone();
}

I feel like having a deja vu ;)

Thanx and regards,
Edgar

On Jul 5, 2007, at 6:33 AM, Edgar Ra. Klein wrote:

Hi guys,

I'm having a problem w/ the Dictionary returned by the DirectAction's form values. More precisely, I have a DirectAction w/ some form values like:
...DirectAction.woa/wa/default?key1=value1&key2=value2


The method request().formValues() returns an NSDictionary looking like that:
{key1 = ("value1"); key2 = ("value2"); }


Unfortunately, the values are wrapped into (" ") and therefore I cannot pass this dictionary to ask the EOUtilities.objectsMatchingValues method for database entries.

Am I doing s.th. wrong or is there an easy way to convert the wrapped values to unwrapped versions?

Thanx,
Edgar
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com


This email sent to email@hidden


--
__ 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
References: 
 >DirectAction: NSDictionary of the form values (From: "Edgar Ra. Klein" <email@hidden>)
 >Re: DirectAction: NSDictionary of the form values (From: "Jerry W. Walker" <email@hidden>)

  • Prev by Date: Re: DirectAction: NSDictionary of the form values
  • Next by Date: Re: DirectAction: NSDictionary of the form values
  • Previous by thread: Re: DirectAction: NSDictionary of the form values
  • Next by thread: Re: DirectAction: NSDictionary of the form values
  • Index(es):
    • Date
    • Thread