Results 1 to 8 of 8
  1. #1
    alok_sharma is offline Member
    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0

    Post how to add Arraylist filter for a jsp page showing results from a servlet-Arraylist

    hello sir/mam, 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,

    Java Code:
    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?

    and from that i want result filtered as this

    Java Code:
    the table which is filter will show as:
    student_id class_id student_name
    1x2001        11         Anurag
    1x2002        11         Arpit
    
    .............going on...

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,791
    Rep Power
    19

    Default

    Change the query you're using to retrieve this stuff form the database?

  3. #3
    alok_sharma is offline Member
    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0

    Smile

    easy to say hard to implement, the database query is in nests of joins and union thus its much harder to implement and also i am using getters and setters and the same query on many places where filter is not needed thus i asked for arraylist filtering ;)

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,791
    Rep Power
    19

    Default

    Nope.
    You filter in the query.
    You must be able to attach a filter to the existing query...joins and unions and all that are irrelevant if you still need to filter the result. Java will be so much slower than than the db at doing this.

  5. #5
    alok_sharma is offline Member
    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0

    Default

    yes i know but still i will emphasize on java, as changing my query will make my project upside down.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,791
    Rep Power
    19

    Default

    Sounds like it's already upside down...anyway, iterate over the List calling the iterators remove method on the ones you don't want.

  7. #7
    alok_sharma is offline Member
    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0

    Default

    i am not using iterators in my code so should i need to re-write it with iterators

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,791
    Rep Power
    19

    Default

    Because an iterator is the correct way for doing this.
    You have an ArrayList (according to your first post), so getting an iterator is easy. As for re-writing, well presumably you have to rework some of it because you need to do this filtering?

Similar Threads

  1. Replies: 2
    Last Post: 11-16-2010, 05:51 PM
  2. About printing Arraylist on JSP page....
    By vaibhavspawar in forum Advanced Java
    Replies: 0
    Last Post: 08-13-2010, 06:52 AM
  3. Unique Filter on search results
    By selva in forum Lucene
    Replies: 0
    Last Post: 02-17-2009, 07:32 AM
  4. Need to filter the hash set which is dtoring my results
    By appi_usa in forum Advanced Java
    Replies: 0
    Last Post: 08-14-2008, 04:34 PM
  5. Replies: 2
    Last Post: 04-21-2008, 11:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •