Re: DirectAction: NSDictionary of the form values

2007-07-05 Thread Jerry W. Walker

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 PROTECTED]
203 278-4085office



___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: DirectAction: NSDictionary of the form values

2007-07-05 Thread Jean-François Veillette
from your description, it look like 'formValues()' wrap all values in  
an array (from the doc).

formValues()
Returns an NSDictionary containing all of the form data
with names for keys and NSArrays containing the value(s)
associated with those keys for values.
so to get "value1", you would do :
String value1 = (String) request().formValues().valueForKey 
("key1").objectAtIndex(0);


Or simply use 'formValueForKey':
String value1 = (String) request().formValueForKey("key1");

- jfv

Le 07-07-05 à 06:33, Edgar Ra. Klein a écrit :


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  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/ 
jean_francois_veillette%40yahoo.ca


This email sent to [EMAIL PROTECTED]


___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: DirectAction: NSDictionary of the form values

2007-07-05 Thread Edgar Ra. Klein

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  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/jerrywwalker% 
40gmail.com


This email sent to [EMAIL PROTECTED]



--
__ Jerry W. Walker,
   WebObjects Developer/Instructor for High Performance Industrial  
Strength Internet Enabled Systems


[EMAIL PROTECTED]
203 278-4085office




___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: DirectAction: NSDictionary of the form values

2007-07-05 Thread Edgar Ra. Klein

Hi,

On 05.07.2007, at 14:56, Jean-François Veillette wrote:


from your description, it look like 'formValues()' wrap all values in

an array (from the doc).
formValues()
Returns an NSDictionary containing all of the form data
with names for keys and NSArrays containing the value(s)
associated with those keys for values.
so to get "value1", you would do :
String value1 = (String) request().formValues().valueForKey 
("key1").objectAtIndex(0);


Or simply use 'formValueForKey':
String value1 = (String) request().formValueForKey("key1");


Thanx for the helpful hint :)

Regards,
Edgar


Le 07-07-05 à 06:33, Edgar Ra. Klein a écrit :


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  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/ 
jean_francois_veillette%40yahoo.ca


This email sent to [EMAIL PROTECTED]


___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: DirectAction: NSDictionary of the form values

2007-07-05 Thread David LeBer


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  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: DirectAction: NSDictionary of the form values

2007-07-05 Thread Jerry W. Walker

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

Regards,
Jerry

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  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/jerrywwalker% 
40gmail.com


This email sent to [EMAIL PROTECTED]



--
__ Jerry W. Walker,
   WebObjects Developer/Instructor for High Performance Industrial  
Strength Internet Enabled Systems


[EMAIL PROTECTED]
203 278-4085office



___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


DirectAction: NSDictionary of the form values

2007-07-05 Thread Edgar Ra. Klein

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  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]