Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

iterator problem

 
Jordan Josh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to All ranchers,
Hope you are fine.
I am trying to iterat ArrayList in jsp page.But I am not getting values from the arraylist.It just only display table header.
Please can somebody help me.

Here is my Action where I am populating the arraylist.


// Jsp Page:
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,


Please tell me one thing whay you store your list in to request and get it on Jsp.


Struts 2 have already OGNL functionality which gives direct to request parameter.

So do one thing declare your list variable at action with getter and setter method you directly get on the Jsp.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not working as written because OGNL doesn't search JEE scopes. You need to explicitly tell OGNL to look in the request scope.

That said, Nishan's point is well-taken--there's no reason to do it like this, twice over. If you *are* dead-set on putting an object in the request it's much, much cleaner to implement RequestAware as opposed to ServletRequestAware. RequestAware doesn't tie your action to the servlet spec, making it significantly easier to test in isolation.

But again, simply exposing your ArrayList as an action property is cleaner, and your original JSP would work.

On a final note, in general we shouldn't define our variables as ArrayList, but as List or Collection: the implementation of the list is a detail we're only rarely concerned about in cases like this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic