Re: Fetch Limit From An Array
Re: Fetch Limit From An Array
- Subject: Re: Fetch Limit From An Array
- From: "Jonathan Fleming" <email@hidden>
- Date: Mon, 19 May 2003 20:41:24 +0100
Hello Art,
Just letting you know how wonderfully well your psudo code worked. It's
great. Apart from a missing closing bracket and an end of statement semi
colon I was able to use it virtually as is. I thought that was good going
for writing it blind.
Many thanks
Jonathan
From: Art Isbell <email@hidden>
To: email@hidden
Subject: Re: Fetch Limit From An Array
Date: Thu, 8 May 2003 10:16:29 -1000
On Thursday, May 8, 2003, at 04:01 AM, Jonathan Fleming wrote:
I am using this code below to get a list of EO's in an array, however, I
only want the fist two sorted items of the array to show... how do I do
this? Or should I be using a fetchSpec instead?
If the objects you want to display haven't already been or won't likely be
fetched when their relationship fault fires, you could use a fetch limit
configured to sort and to limit the number of objects fetched to 2. But
I'll assume that these objects will be fetched at some point so I'll fire
their relationship fault now.
Assuming that "twoClientDatas" is a key bound to some dynamic element's
"list" key, I'd implement twoClientDatas() so it wouldn't repeat its work
needlessly during each request/response loop; I'd declare a component
instance variable to cache the two objects to display. If necessary, you
could set this instance variable to null at any time to force refreshing of
this array. The following uncompiled, untested pseudo-code is for
illustration only.
private NSArray _twoClientDatas;
public NSArray twoClientDatas() {
if (_twoClientDatas == null) {
NSArray clientDatas = sortByImagePosition ? sortedClientDatas() :
tbClient().tbClientDatas();
// Protect against java.lang.IndexOutOfBoundsException.
_twoClientDatas = clientDatas.subarrayWithRange(new NSRange(0,
Math.min(clientDatas.count(), 2));
}
return _twoClientDatas
}
public NSArray sortedClientDatas() {
EOSortOrdering imagePositionSortOrdering =
EOSortOrdering.sortOrderingWithKey("imagePosition",
EOSortOrdering.CompareAscending);
NSArray sortOrderings = new NSArray(imagePositionSortOrdering);
return EOSortOrdering.sortedArrayUsingKeyOrderArray(
tbClient().tbClientDatas(), sortOrderings);
}
public WOComponent orderByImagePosition() {
setSortByImagePosition(true);
return null;
}
public void setSortByImagePosition(boolean value) {
sortByImagePosition = value;
}
public boolean getSortByImagePosition() {
return sortByImagePosition;
}
Aloha,
Art
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_________________________________________________________________
On the move? Get Hotmail on your mobile phone http://www.msn.co.uk/msnmobile
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.