• 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: Custom EOSortOrdering for a WODisplayGroup
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom EOSortOrdering for a WODisplayGroup


  • Subject: Re: Custom EOSortOrdering for a WODisplayGroup
  • From: Chuck Hill <email@hidden>
  • Date: Thu, 6 May 2010 21:18:10 -0700

Hi Paul,


On May 4, 2010, at 11:47 PM, Johann Werner wrote:

Hi Paul,

if you want to write your own comparator look at ERXComparisonSupport from Wonder how it should be written. Unfortunately you have to register your comparator for a specific class type (e.g. String.class) so it is used automatically in place of the default comparator but this means you can't specify one for solely your number attribute. Perhaps someone has more ideas?

jw


Am 05.05.2010 um 05:04 schrieb Paul Hoadley:

Hello,

Here is the problem I am trying to solve:

1. I have an 'Invoice' entity with a 'number' attribute. The attribute's type is VARCHAR. This is completely intentional, as the client may want the "number" to contain letters at some point. (Pretend the attribute name is "identifier" if it hurts your brain. :-)

2. I want to display the Invoice objects in a WODisplayGroup in a custom order. At the moment, that order is simple: all values for Invoice.number are currently actual numbers. So, for now, I want to cast them to integers, and sort them numerically. (This may change later, as letters may be appended.)

3. Using a standard (array of) EOSortOrdering (Invoice.NUMBER.ascs()), the "numbers" are obviously sorted in ASCII order. {1, 10, 11, 2...} For now, what I want is {1, 2, 3, ... 10, 11, ...}.

This was my first attempt (in Invoice.java):

	private static NSSelector<Integer> numberAsInteger =
			new NSSelector<Integer>("compareNumberAsInteger", new Class[] {
					String.class, String.class });

	public static NSArray<EOSortOrdering> NUMBER_SORT_ORD =
			new NSArray<EOSortOrdering>(new EOSortOrdering(NUMBER_KEY,
					numberAsInteger));

	public static int compareNumberAsInteger(String s1, String s2) {
		Integer i1 = new Integer(s1);
		Integer i2 = new Integer(s2);
		int compare = i1.compareTo(i2);
		if (compare == 0) {
			return NSComparator.OrderedSame;
		} else if (compare < 0) {
			return NSComparator.OrderedAscending;
		} else {
			return NSComparator.OrderedDescending;
		}
	}

But I am obviously misunderstanding the semantics of EOSortOrdering's constructor, because it appears that the NSSelector is being called on String, rather than on Invoice using the String keys:

May 05 11:05:34 PBF[56565] WARN NSLog - <com.webobjects.appserver._private.WOComponentRequestHandler>: Exception occurred while handling request:
com.webobjects.foundation.NSForwardException [java.lang.NoSuchMethodException] Class java.lang.String does not implement method compareNumberAsInteger:java.lang.NoSuchMethodException: Class java.lang.String does not implement method compareNumberAsInteger
[2010-5-5 11:5:34 CST] <WorkerThread10> com.webobjects.foundation.NSForwardException [java.lang.NoSuchMethodException] Class java.lang.String does not implement method compareNumberAsInteger:java.lang.NoSuchMethodException: Class java.lang.String does not implement method compareNumberAsInteger
at com .webobjects .foundation .NSForwardException ._runtimeExceptionForThrowable(NSForwardException.java:41)
at com.webobjects.eocontrol.EOSortOrdering $ ComparisonSupport._compareWithArbitrarySelector(EOSortOrdering.java: 553)
at com.webobjects.eocontrol.EOSortOrdering $ComparisonSupport.compareValues(EOSortOrdering.java:545)
at com.webobjects.eocontrol.EOSortOrdering $_SingleValueComparator.compare(EOSortOrdering.java:373)


What am I missing here? I can write an NSComparator for these number-as-string keys, if that's what's required, but then what do I do with that? What I want is the EOSortOrdering for the WODisplayGroup (don't I?), I don't see where the comparator would fit in.

As a workaround, I can add this to Invoice.java:

	public Integer numberAsInteger() {
		return new Integer(number());
	}

and then pass:

new EOSortOrdering("numberAsInteger", EOSortOrdering.CompareAscending)

to the WODisplayGroup. But that's only going to work while I know the attribute values are integers-as-strings. What I need is to be able to customise the comparison myself to guard against the format of the values changing in the future.

(There's an old thread here:

http://lists.apple.com/archives/webobjects-dev/2004/Oct/msg00271.html

which poses a very similar problem. What I need is for Chuck to expand on his response: "3. Create a new comparator that does what you want." :-) Where do I put that comparator, Chuck?)


You can just chalk that up to "vague theoretical mumblings unrelated to the actual problem at hand" (aka need more coffee). NSComparator is great, but can't be used directly in this situation.


Chuck


-- Chuck Hill Senior Consultant / VP Development

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects








_______________________________________________
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


  • Follow-Ups:
    • Re: Custom EOSortOrdering for a WODisplayGroup
      • From: Paul Hoadley <email@hidden>
References: 
 >Custom EOSortOrdering for a WODisplayGroup (From: Paul Hoadley <email@hidden>)
 >Re: Custom EOSortOrdering for a WODisplayGroup (From: Johann Werner <email@hidden>)

  • Prev by Date: Re: ERModernLook
  • Next by Date: Re: Custom EOSortOrdering for a WODisplayGroup
  • Previous by thread: Re: Custom EOSortOrdering for a WODisplayGroup
  • Next by thread: Re: Custom EOSortOrdering for a WODisplayGroup
  • Index(es):
    • Date
    • Thread