How to filter arraylist results in servlet-jsp/jsp-servlet?
-
hello friends in my project i have an arraylist showing results in a jsp page table of given contents of database, i want to add a filter to it to show only the matched contents from list,
the table which is coming out is as:
student_id class_id student_name
1x0001 10 Ashish
1x2001 11 Anurag
1x2002 11 Arpit
1x0001 10 Alok.............going on...
but i want the result to display page only for class_id::11 and remove other results how to do that?
greatest things can be achieved with small but innocent ideas :)
-
hello friends in my project i have an arraylist showing results in a jsp page table of given contents of database, i want to add a filter to it to show only the matched contents from list,
the table which is coming out is as:
student_id class_id student_name
1x0001 10 Ashish
1x2001 11 Anurag
1x2002 11 Arpit
1x0001 10 Alok.............going on...
but i want the result to display page only for class_id::11 and remove other results how to do that?
greatest things can be achieved with small but innocent ideas :)
easy.. i think you're setting the table via a TableModel:
new AbstractTableModel() {
public String getColumnName(int col) {
return columnNames[col].toString();
}public int getRowCount() { return rowData.length; } public int getColumnCount() { return columnNames.length; } public Object getValueAt(int row, int col) { return rowData\[row\]\[col\]; } public boolean isCellEditable(int row, int col) { return true; } public void setValueAt(Object value, int row, int col) { rowData\[row\]\[col\] = value; fireTableCellUpdated(row, col); }
}
- While filling the table you can select the rows to be added to the table by a simple mechanism. This would not modify the ArrayList. - Also you can set up a filtered, temporary ArrayList and give that one to the table. - check this filtering @ oracle.com JAVA tutorials Choose your way and keep things easy (comments help...) regards, Torsten
I never finish anyth...
-
easy.. i think you're setting the table via a TableModel:
new AbstractTableModel() {
public String getColumnName(int col) {
return columnNames[col].toString();
}public int getRowCount() { return rowData.length; } public int getColumnCount() { return columnNames.length; } public Object getValueAt(int row, int col) { return rowData\[row\]\[col\]; } public boolean isCellEditable(int row, int col) { return true; } public void setValueAt(Object value, int row, int col) { rowData\[row\]\[col\] = value; fireTableCellUpdated(row, col); }
}
- While filling the table you can select the rows to be added to the table by a simple mechanism. This would not modify the ArrayList. - Also you can set up a filtered, temporary ArrayList and give that one to the table. - check this filtering @ oracle.com JAVA tutorials Choose your way and keep things easy (comments help...) regards, Torsten
I never finish anyth...
well just to be clear, this question is not related to swing its related to servlet J2EE, A very similar example of my case is here link[^] which is returning only names and id of people but in my case its name ,id, class id thus i have to filter the data as per my needs, anyways i am going to see the arraylist sorting method in your given link.