reset password
Author Message
yurimuradyan
Posts: 42
Posted 11:32 Apr 14, 2009 |

Dr. Sun,

I am trying to return the size() property of a List to be able to use it with JSTL, but when I try to do this I get a NullPointerException. I am using a List<Comment> (class I defined myself). I created an integer variable called numOfComments, and set up getter/setter for it. It the getter I try to return comments.size(). Am I missing something?

yurimuradyan
Posts: 42
Posted 11:43 Apr 14, 2009 |

Figured it out (wasn't checking for null lists). Works now. Should have looked closer before posting.

Last edited by yurimuradyan at 11:44 Apr 14, 2009.
jadiagaurang
Posts: 53
Posted 03:22 Apr 15, 2009 |

I also have List<comment> as one atribute of blog. I have created getter and setter but I can not figure out that how to count size of list in JSP page. I googled it but could not find proper solution. Frown

cysun
Posts: 2935
Posted 07:35 Apr 15, 2009 |
jadiagaurang wrote:

I also have List<comment> as one atribute of blog. I have created getter and setter but I can not figure out that how to count size of list in JSP page. I googled it but could not find proper solution. Frown

See the GuestBook example in Servlet and JSP Rview.

jadiagaurang
Posts: 53
Posted 08:24 Apr 15, 2009 |

I was confused because I can have many object in list of blog and each blog object has list of comment. So, I should not hard code size of comment list by using setAttribute method. I found one example of JSTL functions. Here is URL: http://www.coderanch.com/t/288976/JSP/java/size-list-JSTL. I used it and till now working good.