Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reiterating tags

 
Bob Dunn
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to create a new tag class to display an array list. There is an error on line lineItems = product.getProduct(); Any help would be great..

ProductsTags.java



ProductsServlet


products.java

 
fred rosenberger
lowercase baba
Bartender
Posts: 12122
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing here, since you didn't tell us what the error was (that would have been a big help, since the error message tells you exactly what is wrong).

Where is the getProduct() method defined?
 
Bob Dunn
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that's the problem. The getProduct isn't defined. I'm not sure what this should be but it should be referencing the arraylist in the ProductsServlet.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12122
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you're not sure what WHAT should be?

getProduct() is a method. since you are assigning what it returns to a LineItem, the method has to return one of those.
 
Bob Dunn
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the products servlet, it loads an array list of products objects. In the tag, i want to read this array list. the getProduct method isn't defined anywhere so it's not correct. I had it as getProducts but it didn't work either. I thought it would correspond to the ArrayList line in the products servlet which has getProducts. i have a disconnect somewhere. Thanks in advance for any help.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12122
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't call a method that doesn't exist.

You have created a class called "Products" - therefore, you control what methods exist and what don't for the Products class.

So, I see two options:

1) don't call the getProducts() method, since it doesn't exist.
2) Write a method in your Products class call "getProducts" (or getProduct, if that's what you need) and make it do what you want.

I am not a servlet guy, so I can't address that part.

What exactly do you expect the method getProducts to do? What should it return?
 
Bob Dunn
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should return the objects in the arraylist that is stored as an attribute of the session object in the ProductsServlet class.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12122
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bob Dunn wrote:It should return the objects in the arraylist that is stored as an attribute of the session object in the ProductsServlet class.

so, write it and make it do that.
 
Bob Dunn
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well... if i knew how to do that I wouldn't be asking and obviously you don't know how to either or else your answer would have been more appropriate. Thanks for wasting my time and providing no assistance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic