This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP, beans and sharing ArrayLists

 
Chris Baty
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic