I recently created a orderedSelectItems tag that took comparator
components as children.
The component implementation was open so long as it implemented this interface:

public interface ComparatorSource {
   public Comparator getComparator();
Note: I'm not entirely certain if this is applicable since I haven't
looked at SortableModel, but it is on the subject of JSF and sorting.

I've created a <propertyComparator> component that compares by a property path.

<orderedSelectItems value="#{bean.items}">
   <propertyComparator property="accessor.path.to.property"
        descending="sortdirection: true or false"
       useNullForUnresolvedProperties="true ignores null or illegal
path components"/>
</orderedSelectItems>

I've been thinking it'd be nice if UIData components would also be
able to use the same comparator strategies.    Perhaps by specifying a
"comparator" facet and attaching one or  more comparator
implementations as children to it.

This is something I may take a look at implementing for the Tomahawk
UIData components.


On 1/21/07, Adam Winer <[EMAIL PROTECTED]> wrote:
+1 to having *some* solution here.

Perhaps SortableModel should have support for Comparators
(which is implemented by Collators).  One possible API would be:

  public Map<String, Comparator> getComparators();

... so you could do:

  Collator collator =
    
Collator.getInstance(FacesContext.getCurrentInstance().getViewRoot().getLocale());
  model.getComparators().put("myField", collator);

This would require manual setup per field, though.  But
I think it would solve the problem we have right now where
we don't know how to sort a column if the first entry
is null.

Another possibility is adding a protected hook:

  protected Comparator getComparator(
    String fieldName, Object sampleObject);

Manual setup again, but at least you could write one
class that had it turned on for all Strings.

And yet another way of doing this would be automatically using
Collator.getInstance() for Strings, or adding a flag to turn
it on - I'm not well-versed in the performance implications
of using Collator, and would want to know before turning this
on by default.  And it's not obvious that you would always want it on -
I could imagine that some strings might want to be sorted
in a non-internationalized manner.

Ideas, preferences?

-- Adam



On 1/21/07, Martin Koci <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I trying to use SortableModel instead my own implementation, but it has
> one big issue - doesn't support Czech language.
>
> We (here in the middle of Europe) have very special rules for sorting
> words which cannot be done with simple:
> value1.toString().compareTo(value2.toString())
>
>
> Fortunately java has a build-in support with Collator:
>
> Collator collator =
> 
Collator.getInstance(FacesContext.getCurrentInstance().getViewRoot().getLocale());
> collator.compare(value1, value2);
>
> Should I create a JIRA issue?
>
>
> Thanks,
>
> Martin
>
>
> For experts and czech native speakers :D
> http://146.102.68.23/kizi/IKSy/kap12.htm
>
>
>

Reply via email to