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

displaying contents of collection of beans using JSTL  RSS feed

 
JohnZ Smythe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Hi, I'm new to programming with JSTL (and with web programming in general). I'm trying to display the contents of a collection of beans using JSTL. The bean objects sit inside an array list. Within my .jsp file, I want to access the list, then once inside the list, iterate through to access each bean's contents to display in a table. I can do the html part...but don't know how to access the collection and then the beans. Thank you in advance for taking the time to help me.

- john

Code snippet to set up array list:

====================
BookBean.java


[ August 02, 2005: Message edited by: JohnZ Smythe ]

[ August 02, 2005: Message edited by: JohnZ Smythe ]
[ August 02, 2005: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First things first. In:



What is books? It's not defined.

I'm going to assume that it's a typo and that it should have been list. (Please be careful about these sorts of things).

Next... why session scope? Does the list need to hang around for multiple requests? If you are merely sending the list from a controller to its page, request scope is customary.

To iterate over the list is easy:



Within the scope of the forEach tag, the scoped variable book will represent the subsequent entries in the list.

Within the loop accessing the bean's properties is equally simnple. Assuming JSP 2.0 (you didn't say), the EL expressions would be along the lines of: ${book.bookId}, ${book.title}, ${book.price} and so on.

So it's easy to format an HTML table by placing the TR elements inside the forEach and emitting the TD elements within it that represent the columns for the various book properties.
[ August 02, 2005: Message edited by: Bear Bibeault ]
 
JohnZ Smythe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear, I am replying to let you know that.....

I AM A F__KING MORON!!!

Here's what my jsp code looked like before my initial post:


Here's the text that was outputted in the browser:

{book.bookId} {book.title} {book.price} {book.categoryId} {book.bookId} {book.title} {book.price} {book.categoryId} {book.bookId} {book.title} {book.price} {book.categoryId}

DUH!!!

I forgot the $$$$$$$$$$$$$$$

Two hours of my life down the toilet.

Thanks for your help though.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Someday I'll tell you the semi-colon story...

Welcome to the Ranch!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!