Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Issue with ArrayList and JSTL  RSS feed

 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Experts,

I Have an arraylist with size 10. This arraylist is populated from the DB.

I am using JSTL to display the contents of this ArrayList on the JSP using this code:



but instead of displaying 10 items, its displaying lot more than that. (ArrayList contains few nulls as well included in total count of 10)

Below is the method which populates the ArrayList and the snapshot of outpout I am getting.

jstl_snap.PNG
[Thumbnail for jstl_snap.PNG]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's up with the crazy indentation? Makes it very hard to read your code.

Look at this line very carefully:
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

I am Sorry for that indentation, not sure how that happened. Actually the in the DB Table, Groups column contains ten items as shown in this snapshot.

So I can get rid of nulls with the query and I only want to display AA, BB, CC, DD on the page.

groups.PNG
[Thumbnail for groups.PNG]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you inspect the line I indicated?
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops,,

Thank you so much Sir :-)

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now, what is your output?

Any yes, don't put nulls into the list in the first place.
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I am not getting any nulls Sir.

I am still in the learning phase... Am I implementing the MVC model correctly here or would you recommend any changes?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aman Singh wrote:Am I implementing the MVC model correctly here or would you recommend any changes?

There's no way to tell from what you've posted. But here are some points:
  • It's good that you are using JSTL/EL and not scriptlets
  • It's good that you are doing the DB code in Java rather than in the JSP
  • It's good that you are not trying pass a result set around and copying the data to the array list
  • It would be good if that database code were not in the presentation layer (that is in a servlet or other UI element) -- it should be part of the model layer. Can't tell from what you've posted.

  •  
    Aman Singh
    Ranch Hand
    Posts: 57
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you Sir.

    My Db Code and ArrayList population is in the Back layer.

    In my servlet, I am only invoking the methods to get these ArrayLists and setting in the context variable.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65830
    134
    IntelliJ IDE Java jQuery Mac Mac OS X
     
    Aman Singh
    Ranch Hand
    Posts: 57
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Wow.. I am learning :-)

    I remember those days, when I used to post here, and first comment that was due from all you senior folks was:

    "Do NOT NOT NOT use scriplet"
    "Do not make DB connection in your JSP"
    "No Db Connection in your servlet"


    Thanks
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65830
    134
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Learning is good!
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!