• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sortby

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am using sorting for the list in datatable, using property "sortby"

for example, if i have following records

932
1122
912
1234


While doing ascending order, it sorts as follows

1122
1234
912
932

which is not correct, 912 and 932 should appear first. How should i resolve this problem??





 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Naveen,
Based on the information you have provided, I'm guessing you are sorting strings and not numbers.
If my guess is correct then I know of two possibilities available to you.
  • Change the strings to numbers.
  • Keep as strings but insert leading zeros.

  • Using the second option, your list would appear as:

    0912
    0932
    1122
    1234

    Hope this helps.

    Good Luck,
    Avi.
     
    naveen gupta
    Ranch Hand
    Posts: 129
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    yeah, i think you are right. I will check that. thanks
     
    naveen gupta
    Ranch Hand
    Posts: 129
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Yeah, because the variable is of String type

    Now i am looking for solution to solve this

    I have to define this variable as "String" only and i can't append 0's to the value

    Is there any other solution for this problem

    like while displaying or while sorting can we tell it to consider the values as Number???
     
    Avi Abrami
    Ranch Hand
    Posts: 1143
    1
    Eclipse IDE Oracle Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Naveen,
    You asked:


    Is there any other solution for this problem like while displaying or while sorting can we tell it to consider the values as Number?


    I suggest method sort in class java.util.Collections.

    Good Luck,
    Avi.
     
    naveen gupta
    Ranch Hand
    Posts: 129
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    yeah, but again i have to use the same in Java code

    But i want some way to interpret the string as Integer in the JSF code itself
     
    Ranch Hand
    Posts: 200
    Eclipse IDE Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Your best bet is to sort the items in the backing bean and then display them on your page. On your view, are you using some kind of list?
     
    naveen gupta
    Ranch Hand
    Posts: 129
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    yes, i am using ArrayList on my view page

    i am using sortBy attribute to sort, the feature provided by RichFaces for dataTable

    anyway, i have changed type from String to Integer
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic