Re: Custom EOSortOrdering for a WODisplayGroup
Re: Custom EOSortOrdering for a WODisplayGroup
- Subject: Re: Custom EOSortOrdering for a WODisplayGroup
- From: Timo Hoepfner <email@hidden>
- Date: Thu, 6 May 2010 09:11:42 +0200
I did something similar before. I basically took the "Strings" class
from here:
<http://weblogs.java.net/blog/skelvin/archive/2006/01/natural_string.html
>
and wired it up in a EOSortOrdering.ComparisonSupport subclass derived
from ERXComparisonSupport. I attached a cleaned up version of the file.
Then add something like this to your Application (if it extends
ERXApplication):
@Override
public void finishInitialization() {
super.finishInitialization();
NaturalOrderStringSortSupport.initialize();
}
As Johann pointed out before, this is then globally used for all
String sorting.
HTH,
Timo
Attachment:
NaturalOrderStringSortSupport.java
Description: Binary data
Attachment:
Strings.java
Description: Binary data
Am 06.05.2010 um 02:31 schrieb Paul Hoadley:
On 05/05/2010, at 4:17 PM, Johann Werner wrote:
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?
Thanks Johann.
Maybe "WODisplayGroup" in the subject is turning people off
here. :-) Say I just want an EOSortOrdering that can solve this
problem:
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, ...}.
It only needs to work for in-memory sorts.
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?)
I can write the code to do the comparison, I just don't understand
how to plumb it all together.
--
Paul.
http://logicsquad.net/
_______________________________________________
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
_______________________________________________
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