You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Tomislav Jakopec <tj...@orka.hr> on 2007/01/16 08:14:34 UTC

datatable sortable order problem for non english languages

Hi, I try first posting at Users forum but no answer, hope here will be a
answer.

I have small problem and I don't now how to handle.
So far I write my own Comparator in witch I sorted according to Collator
with locale form FacesContext

Collator collator = Collator.getInstance(
                                               
FacesContext.getCurrentInstance().getViewRoot().getLocale());
My sort order was fine, Croatian letters where sorted alphabet.

Now there is possibility to tel whole datatable sortable="true" and I don't
have to write commandSortHeader tag.

Problem: sort is alphabet in english language, not croatian and
FacesContext.getCurrentInstance().getViewRoot().getLocale() is croatian

Is there a way to solve this problem or this is new feature for developer to
implement?
-- 
View this message in context: http://www.nabble.com/datatable-sortable-order-problem-for-non-english-languages-tf3019397.html#a8385686
Sent from the My Faces - Dev mailing list archive at Nabble.com.


Re: datatable sortable order problem for non english languages

Posted by Catalin Kormos <ca...@gmail.com>.
Hi,

Ok, i see TOMAHAWK-864 now. Thanks.

Regards,
Catalin

On 1/18/07, Tomislav Jakopec <tj...@orka.hr> wrote:
>
> hi
> I was succesfully log in jira and post issue.
> --
> View this message in context:
http://www.nabble.com/datatable-sortable-order-problem-for-non-english-languages-tf3019397.html#a8425747
> Sent from the My Faces - Dev mailing list archive at Nabble.com.
>
>

Re: datatable sortable order problem for non english languages

Posted by Tomislav Jakopec <tj...@orka.hr>.
hi
I was succesfully log in jira and post issue.
-- 
View this message in context: http://www.nabble.com/datatable-sortable-order-problem-for-non-english-languages-tf3019397.html#a8425747
Sent from the My Faces - Dev mailing list archive at Nabble.com.


Re: datatable sortable order problem for non english languages

Posted by Catalin Kormos <ca...@gmail.com>.
Hi,

The Jira issue tracker for Tomahawk you can find at
http://issues.apache.org/jira/browse/TOMAHAWK
. It should  be pretty straightforward after you sign up, if you don't have
an account there already, to create a new issue. Not much to worry about.

I'm running a little to short on time right now, so i can't make a promise,
but it should be resolved this week, and with the next nightly build you can
have it then.

The nightly builds can be found at:
http://people.apache.org/repo/m2-snapshot-repository/org/apache/myfaces/tomahawk/tomahawk/1.1.5-SNAPSHOT/

Regards,
Catalin

On 1/17/07, Tomislav Jakopec <tj...@orka.hr> wrote:
>
>
> Hi!
>
> I look the code and try something
>
> public int compare(Object o1, Object o2)
>         {
>
>
>             int index1 = ((Integer) o1).intValue();
>             int index2 = ((Integer) o2).intValue();
>
>             _model.setRowIndex(index1);
>             Object value1 = getPropertyValue(_prop);
>
>             _model.setRowIndex(index2);
>             Object value2 = getPropertyValue(_prop);
>
>             if (value1 == null)
>                 return (value2 == null) ? 0 : -1;
>
>             if (value2 == null)
>                 return 1;
>
>          //my code
>             if(value1 instanceof java.lang.String){
>                 Collator collator = Collator.getInstance(
>
> FacesContext.getCurrentInstance().getViewRoot().getLocale());
>                                 collator.setStrength(Collator.PRIMARY);
>                        return collator.compare(value1, value2);
>             }
>        //end my code
>
>             // ?? Sometimes, isSortable returns true
>             // even if the underlying object is not a Comparable.
>             // This happens if the object at rowIndex zero is null.
>             // So test before we cast:
>             if (value1 instanceof Comparable)
>             {
>                 return ((Comparable) value1).compareTo(value2);
>             }
>             else
>             {
>                 // if the object is not a Comparable, then
>                 // the best we can do is string comparison:
>                 return value1.toString().compareTo(value2.toString());
>             }
>         }
>
> I don't now how to report to jira, could you be so kind and do it?
> When will change be avaiable for download and where?
>
> Thanks lot. This will reduce my code for about 10 % :)
> --
> View this message in context: http://www.nabble.com/datatable-sortable-order-problem-for-non-english-languages-tf3019397.html#a8410212
>
> Sent from the My Faces - Dev mailing list archive at Nabble.com.
>
>

Re: datatable sortable order problem for non english languages

Posted by Tomislav Jakopec <tj...@orka.hr>.
Hi!

I look the code and try something

 public int compare(Object o1, Object o2) 
        {
        	
        	
            int index1 = ((Integer) o1).intValue();
            int index2 = ((Integer) o2).intValue();
            
            _model.setRowIndex(index1);
            Object value1 = getPropertyValue(_prop);
            
            _model.setRowIndex(index2);
            Object value2 = getPropertyValue(_prop);
            
            if (value1 == null)
                return (value2 == null) ? 0 : -1;
            
            if (value2 == null)
                return 1;
            
         //my code
            if(value1 instanceof java.lang.String){
            	Collator collator = Collator.getInstance(
						FacesContext.getCurrentInstance().getViewRoot().getLocale());
				collator.setStrength(Collator.PRIMARY);
		       return collator.compare(value1, value2);
            }
       //end my code
            
            // ?? Sometimes, isSortable returns true
            // even if the underlying object is not a Comparable.
            // This happens if the object at rowIndex zero is null.
            // So test before we cast:
            if (value1 instanceof Comparable) 
            {
                return ((Comparable) value1).compareTo(value2);
            } 
            else 
            {
                // if the object is not a Comparable, then
                // the best we can do is string comparison:
                return value1.toString().compareTo(value2.toString());
            }
        }   

I don't now how to report to jira, could you be so kind and do it? 
When will change be avaiable for download and where?

Thanks lot. This will reduce my code for about 10 % :)
-- 
View this message in context: http://www.nabble.com/datatable-sortable-order-problem-for-non-english-languages-tf3019397.html#a8410212
Sent from the My Faces - Dev mailing list archive at Nabble.com.


Re: datatable sortable order problem for non english languages

Posted by Catalin Kormos <ca...@gmail.com>.
Hi there,

If you look in the
org.apache.myfaces.component.html.ext.SortableModel(inner class Comp),
the default comparator that is used to sort the values
in a given column, will compare the values as Comparable if they implement
that interface, if not it will compare them as simple strings, obtained by
toString().

This makes me think that the usage of the Collator class to compare those
strings would do it, thanks for pointing that out, btw. It would be great if
you could open a Jira issue for this, and even greater, if possible, to
provide a patch, it would be of great help having this resolved faster.

Regards,
Catalin

On 1/16/07, Tomislav Jakopec <tj...@orka.hr> wrote:
>
>
> Hi, I try first posting at Users forum but no answer, hope here will be a
> answer.
>
> I have small problem and I don't now how to handle.
> So far I write my own Comparator in witch I sorted according to Collator
> with locale form FacesContext
>
> Collator collator = Collator.getInstance(
>
> FacesContext.getCurrentInstance().getViewRoot().getLocale());
> My sort order was fine, Croatian letters where sorted alphabet.
>
> Now there is possibility to tel whole datatable sortable="true" and I
> don't
> have to write commandSortHeader tag.
>
> Problem: sort is alphabet in english language, not croatian and
> FacesContext.getCurrentInstance().getViewRoot().getLocale() is croatian
>
> Is there a way to solve this problem or this is new feature for developer
> to
> implement?
> --
> View this message in context:
> http://www.nabble.com/datatable-sortable-order-problem-for-non-english-languages-tf3019397.html#a8385686
> Sent from the My Faces - Dev mailing list archive at Nabble.com.
>
>

Re: datatable sortable order problem for non english languages

Posted by Catalin Kormos <ca...@codebeat.ro>.
Hi there,

If you look in the org.apache.myfaces.component.html.ext.SortableModel
(inner class Comp), the default comparator that is used to sort the values
in a given column, will compare the values as Comparable if they implement
that interface, if not it will compare them as simple strings, obtained by
toString().

This makes me think that the usage of the Collator class to compare those
strings would do it, thanks for pointing that out, btw. It would be great if
you could open a Jira issue for this, and even greater, if possible, to
provide a patch, it would be of great help having this resolved faster.

Regards,
Catalin

On 1/16/07, Tomislav Jakopec <tj...@orka.hr> wrote:
>
>
> Hi, I try first posting at Users forum but no answer, hope here will be a
> answer.
>
> I have small problem and I don't now how to handle.
> So far I write my own Comparator in witch I sorted according to Collator
> with locale form FacesContext
>
> Collator collator = Collator.getInstance(
>
> FacesContext.getCurrentInstance().getViewRoot().getLocale());
> My sort order was fine, Croatian letters where sorted alphabet.
>
> Now there is possibility to tel whole datatable sortable="true" and I
> don't
> have to write commandSortHeader tag.
>
> Problem: sort is alphabet in english language, not croatian and
> FacesContext.getCurrentInstance().getViewRoot().getLocale() is croatian
>
> Is there a way to solve this problem or this is new feature for developer
> to
> implement?
> --
> View this message in context:
> http://www.nabble.com/datatable-sortable-order-problem-for-non-english-languages-tf3019397.html#a8385686
> Sent from the My Faces - Dev mailing list archive at Nabble.com.
>
>