aspose file tools*
The moose likes JSP and the fly likes jstl, ArrayLists and object instances? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jstl, ArrayLists and object instances?" Watch "jstl, ArrayLists and object instances?" New topic
Author

jstl, ArrayLists and object instances?

Chris Baty
Ranch Hand

Joined: Nov 23, 2008
Posts: 30
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

Joined: Feb 20, 2001
Posts: 3695

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

Joined: Jan 10, 2002
Posts: 60045
    
  65

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Chris Baty
Ranch Hand

Joined: Nov 23, 2008
Posts: 30
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

Joined: Jan 10, 2002
Posts: 60045
    
  65

A bean id is automatically created as scripting, as well as a scoped variable in the specified scope.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jstl, ArrayLists and object instances?
 
Similar Threads
Why should an array variable be declared as a Bean
JSP, beans and sharing ArrayLists
jdbc connection in jsp
trying to submit a form using hyperlink (href)
Jstl foreach iterate over arraylist containing map object using paramvalues