This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am working on a project where we using technologies like Java, velocity etc. I am working on a task where I display data by means of a HTML table having 5 columns with 1st column being checkbox selection. I need some help with this - "If the user is going to select checkboxes on 1,3,5 rows then I need to move those selected rows on the top of this table." I am getting a Java Object and looping thru that Java Object in the velocity file using For Loop to display the data in this HTML table. someone advised me using Java comparator I can do this but I dont have much idea about it. Can someone please provide me code for how to do this. I very much appreciate your help.
I am not sure you need a Comparator; all you need to do is get your Row object to return whether your box is selected, maybe with a public boolean checkboxIsSelected() method. Then you can sort on whether the boxes are selected. Consider true as greater than false in your sort method. If you are using a Comparator, that is what you would have to compare: whether you have false-true (return -1) or true-false (return 1) or the two the same (return 0). You can find the details of Comparator here.