sorting - Need to sort a list using Wicket -


i working on simple program, looking this:

public class wicketapplication extends webapplication implements comparable<object>{  private list<person> persons = arrays.aslist(         new person("mikkel", "20-02-91", 60169803),         new person("jonas", "02-04-90", 86946512),         new person("steffen", "15-07-90", 12684358),         new person("rasmus", "08-12-93", 13842652),         new person("michael", "10-10-65", 97642851));  /**  * @see org.apache.wicket.application#gethomepage()  */ @override public class<? extends webpage> gethomepage() {     return simpleview.class; }  public static wicketapplication get() {     return (wicketapplication) application.get(); }  /**  * @return @see org.apache.wicket.application#init()  */ public list<person> getpersons() {     return persons; }  public list<person> getsortedlist(){     return collections.sort(persons);     //this won't work before implementing comparator know, how?? }  @override public void init() {     super.init();      // add configuration here }  @override public int compareto(object o) {     throw new unsupportedoperationexception("not supported yet."); //to change body of generated methods, choose tools | templates. } } 

that class put people list.

public class simpleview extends simpleviewpage {   public simpleview() {     listview persons = new listview("persons", getpersons()) {         @override         protected void populateitem(listitem item) {             person person = (person) item.getmodelobject();             item.add(new label("name", person.getname()));             item.add(new label("birthdate", person.getbirthdate()));             item.add(new label("phone", person.getphone()));         }     };     add(persons);     add(new label("size", "number of people " + getpersons().size())); } } 

and here people. basicly want program show table data(this works). want able sort them. can't life of me figure out. i'm still rather new @ programming, , want have button below table can sort on name, bday or phone number. thinking trying comparable, can't remember well, , not sure how works wicket..

thanks in advance :)

what need dataview component, provides support need sorting (and paging, should require later on).

here's working example, if click on "source code" link in top right corner, can see of things want sortable table work out of box. need create suitable data provider.

if use dataview sortabledataprovider, don't need worry writing own dynamic comparator. (which not terribly hard task itself, it's easy wrong.)


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -