File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes JSP, beans and sharing ArrayLists Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP, beans and sharing ArrayLists" Watch "JSP, beans and sharing ArrayLists" New topic
Author

JSP, beans and sharing ArrayLists

Chris Baty
Ranch Hand

Joined: Nov 23, 2008
Posts: 30
Hi guys,
I'm at it again, probably doing it the wrong way. The following code works great;


It lists an ArrayList that's generated by a bean. Great. Later, I wanted to pick off the first object in that ArrayList so I repeated the same code and I keep getting null stuff. I tried tsSale.get(0).object.getUname() without success. I tried putting the ArrayList into a session bean object. Nope.

Two questions:

1. Can you put an ArrayList into a session bean?

2. Can one bean create instances/objects of another session bean that can be accessed throughout the session?

3. Should I be using Struts?

Thanks.

Chris
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Originally posted by Chris Baty:
Hi guys,
I'm at it again, probably doing it the wrong way. The following code works great;

We're rather interested in the code which didn't work.

It lists an ArrayList that's generated by a bean. Great. Later, I wanted to pick off the first object in that ArrayList so I repeated the same code and I keep getting null stuff. I tried tsSale.get(0).object.getUname() without success. I tried putting the ArrayList into a session bean object. Nope.

You need to elaborate a bit more about "I keep getting null stuff".


Two questions:

1. Can you put an ArrayList into a session bean?

Yes.


2. Can one bean create instances/objects of another session bean that can be accessed throughout the session?

It can, yes. But if it is recommendable? Can't say more as long as your functional requirement is unclear.

3. Should I be using Struts?

Not necessarily. Get a good grasp on plain Java/JSP/JSTL/EL first.
Chris Baty
Ranch Hand

Joined: Nov 23, 2008
Posts: 30
Here's a test JSP that doesn't work but is the same code I used before:


I'm trying to pick off the first object and put the uname element into a session bean. This is the method that generates the ArrayList:



Here, I tried to put the ArrayList into another session bean, without apparerent success. I'm learning a lot but becoming frustrated.


Thanks.

Chris
Chris Baty
Ranch Hand

Joined: Nov 23, 2008
Posts: 30
I decided to go back to the basics, so I wrote a simple bean:


Then I wrote a JSP:


It worked Great. Hope this helps others.

Chris
 
 
subject: JSP, beans and sharing ArrayLists