• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Iterator problem

 
michell o'brien
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure where i am going wrong. But my code below is accessiong the "menArraylist" 2wice and every time only the last element is being diplayed. when I try to display the values of menArrayList in the Action class it is showing me the right values. Can anybody tell me where i am going wrong.



and my menform class has

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.
 
michell o'brien
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I have the link for the Struts forum please
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:I have moved this post there for you.

I don't see anything obvious; you should post the rest of the code otherwise figuring anything out is essentially impossible.

Wait, did you say menArrayList is in your form bean? Isn't it supposed to be in scope?

Btw, it's recommended to use JSTL tags where functionality overlaps w/ Struts 1 tags.
 
michell o'brien
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
menArraylist is the collection from Menform class. And it holds String values.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That didn't really answer any of my questions.
 
michell o'brien
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys can anybody please help me in solving this issue. I have already spent enough time in this.
 
michell o'brien
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry Mr.David Newton then i did not get you?
 
michell o'brien
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My action class. "Menaction.java"




Menform.java



menu.jsp



 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're always adding the same object to the list.
 
michell o'brien
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry i did not get you
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are at least a couple of issues with this code:

1) Line 4 adds the same object to the list, over and over. Line 2 changes a property of the object you're adding, so you end up seeing the same value multiple times. This is almost certainly not what you want, and explains why you're seeing the same values.

2) Line 5: There's no reason to set the same list into the session over and over. Just do it once, outside of the loop.

(See how helpful posting the actual code was?)
 
michell o'brien
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir i understood he 2nd point what you mentioned but regarding the first one menlist is


so everytime i add a new value to menlist.setCategory_name I guess it should appened the value. This is what i thought it does.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see that anywhere in your code. If it's not in the loop, you're not making a new object for every item in the result set. If it is in the loop, then why didn't you post the actual code?
 
michell o'brien
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry sir I had written that on top of my rs.next{

}

That was the problem. It was not creating a new object everytime.

Thankyou for being so humble to me and explaining the code what I had written.
Once again Thank you very much :-)
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome--glad I could help.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic