This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jstl, ArrayLists and object instances?

 
Chris Baty
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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.

 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A bean id is automatically created as scripting, as well as a scoped variable in the specified scope.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic