• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jstl, ArrayLists and object instances?

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
I'm trying to use jstl to create an instance of bean a bean object and print the ArrayList of objects. Everything seems to work fine except the print section prints the first instance over-and-over, but the correct number of instances. Any ideas would be appreciated.

 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't use the tags very much, so I'm speculating, but my guess is:

<jsp:useBean id="sh" class="com.bean.SaleHandler" scope="request"/>

That will instantiate, *one time*, a bean of the type SalesHander, and put it in request scope under the 'sh' variable name.

So, even though you've got it inside a loop, and you're adding it to a list,
you can't use the 'usebean' tag to instantiate a new bean every time through the loop. It's just going to re-use the same instance over and over again.

If that's true, then I expect this statement of yours:
> except the print section prints the first instance over-and-over,
is slightly not accurate. it's actually printing the *last* query row, over and over. Right?
[ December 10, 2008: Message edited by: Mike Curwen ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd back off a furlong or two and ditch using the SQL tags in the page altogether and do the database access in model classes delegated to by the page controller.

The JSTL SQL tags are not intended for production use.
[ December 10, 2008: Message edited by: Bear Bibeault ]
 
Chris Baty
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that's what I was thinking that I better handle this in a bean. JSTL makes it so easy though. But I'm curious now: Can a bean id be a variable? Just curious.

Thanks.
Chris
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A bean id is automatically created as scripting, as well as a scoped variable in the specified scope.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic