AID BID count1 count2
AID1 1 3 4
2 4 5
3 4 2
AID2 4 6 10
5 2 4
6 4 6
AID3 7 4 5
8 9 4
THis is the table I am trying to display that is for every AID in ObjA display a list of ObjB s.
I want to display a Sortable data using Wicket DataTable or Listview .I have used the SortableData Provider and it works for simple Objects like
ObjA{
int a;
String b;
}
But I have an Object which has List of Objects within it as field as shown below.
ObjA{
Long aId;
List<ObjB> listObjB;
}
@magomi
Thank you for your response.This is the code and the corresponding Html files. I am using DataTables.
I am not sure how to render the items in the listObjBs (bID,count,count2) in the table for every aID.
What is the right way to add the columns for the listObjBs in the ObjA
***columns.add(new PropertyColumn<ObjA>(Model.of("B ID"), "ObjBCounts.bID",
"ObjBCounts.BID"));
columns.add(new PropertyColumn<ObjA>(Model.of(" Count"), "objBCounts.count"));
columns.add(new PropertyColumn<ObjA>(Model.of("Count2”),"objBCounts.count2"));***
How do I sort on the column bID in the iterator method?
Public class HomePage extends Webpage
private static List<ObjB> listObjBs = Arrays.asList(
new ObjB(15L,2,5),
new ObjB(12L,7,10),
new ObjB(13L,3,5),
new ObjB(10L,6,5));
private static List<ObjA> contacts = Arrays.asList(
new ObjA(1L,listObjBs),
new ObjA(2L,listObjBs),
new ObjA(3L,listObjBs),
new ObjA(4L,listObjBs));
public HomePage(final PageParameters parameters) {
List<IColumn<ObjA>> columns = new ArrayList<IColumn<ObjA>>();
columns.add(new PropertyColumn<ObjA>(Model.of("A ID"), "aID",
"aID"));
Public class HomePage extends Webpage
private static List<ObjB> listObjBs = Arrays.asList(
new ObjB(15L,2,5),
new ObjB(12L,7,10),
new ObjB(13L,3,5),
new ObjB(10L,6,5));
private static List<ObjA> contacts = Arrays.asList(
new ObjA(1L,listObjBs),
new ObjA(2L,listObjBs),
new ObjA(3L,listObjBs),
new ObjA(4L,listObjBs));
public HomePage(final PageParameters parameters) {
List<IColumn<ObjA>> columns = new ArrayList<IColumn<ObjA>>();
columns.add(new PropertyColumn<ObjA>(Model.of("A ID"), "aID",
"aID"));
columns.add(new PropertyColumn<ObjA>(Model.of("B ID"), "ObjBCounts.bID",
"ObjBCounts.BID"));
columns.add(new PropertyColumn<ObjA>(Model.of(" Count"), "objBCounts.count"));
columns.add(new PropertyColumn<ObjA>(Model.of("Count2”),"objBCounts.count2"));
add(new DefaultDataTable<ObjA>("contacts", columns,
new ContactsProvider(), 10));
}
rivate static class ContactsProvider extends SortableDataProvider<ObjA> {
public ContactsProvider() {
setSort("aID", SortOrder.ASCENDING);
}
public Iterator<? extends ObjA> iterator(int first, int count) {
List<ObjA> data = new ArrayList<ObjA>(contacts);
Collections.sort(data, new Comparator<ObjA>() {
public int compare(ObjA o1, ObjA o2) {
int dir = getSort().isAscending() ? 1 : -1;
if ("bID".equals(getSort().getProperty())) {
return dir * (o1.listObjB.get(0).getBID().compareTo(o2.listObjB.get(0).getBID()));
} else {
return dir * (o1.getAID().compareTo(o2.getAID()));
}
}
});
return data.subList(first, Math.min(first + count, data.size()))
.iterator();
}
public int size() {
return contacts.size();
}
public IModel<ObjA> model(ObjA object) {
return Model.of(object);
}
}
<html>
<body>
<table border ="1" cellspacing = "1" wicket:id="contacts" class="contacts"></table>
</body>
</html>
add(new DefaultDataTable<ObjA>("contacts", columns,
new ContactsProvider(), 10));
}
rivate static class ContactsProvider extends SortableDataProvider<ObjA> {
public ContactsProvider() {
setSort("aID", SortOrder.ASCENDING);
}
public Iterator<? extends ObjA> iterator(int first, int count) {
List<ObjA> data = new ArrayList<ObjA>(contacts);
Collections.sort(data, new Comparator<ObjA>() {
public int compare(ObjA o1, ObjA o2) {
int dir = getSort().isAscending() ? 1 : -1;
if ("bID".equals(getSort().getProperty())) {
return dir * (o1.listObjB.get(0).getBID().compareTo(o2.listObjB.get(0).getBID()));
} else {
return dir * (o1.getAID().compareTo(o2.getAID()));
}
}
});
return data.subList(first, Math.min(first + count, data.size()))
.iterator();
}
public int size() {
return contacts.size();
}
public IModel<ObjA> model(ObjA object) {
return Model.of(object);
}
}
<html>
<body>
<table border ="1" cellspacing = "1" wicket:id="contacts" class="contacts"></table>
</body>
</html>
ObjB{
Long bId;
int count;
int count2;
}
It want to display data from ObjA which contains a list of objBs in a Sortable table
Could some one please help me with the wicket markup and and how to populate the columns.
Thank you.
I’m not quite sure but it looks like you are mixing ObjA and ObjB into one table in a way that is not possible. Is it right, you want to show a table of ObjA (at least this is indicated by your first column)? Or do you want to show a table of ObjB (as indicated by the second and third column)?
As long as a table is backed by one list you cannot mix another list into this table.
From my sight you have the following options:
You can define some kind of DTO that has a object mixed from ObjA and ObjB. Something like this:
class Data() {
int objAId;
int objBId;
int count1;
int count2;
…
}
You can use a standard repeating view and implement the sorting into your own data provider.