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

How to use array of beans in jsp

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody, I am Chaitanya, I have a jsp to which an array of beans is passed as a request attribute. I don't know how to declare that bean and how to index. This is what I have written and I am getting an error.


Please help me. Thank you all in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64970
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chaitanya karthikk wrote:I have a jsp to which an array of beans is passed as a request parameter.

Impossible. Request parameters can only be strings. You'll need to explain what you mean by this.

Do you really mean a scoped variable?
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, I am sorry, its not a request parameter, its a request attribute actually.
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chaitanya karthikk wrote:



Can I make a couple of suggestions, firstly you are not required to use the <jsp:useBean .../> or <jsp:getProperty... /> tags if you are using EL which you seem to be using.

Next I'd change this line



In this firstly you have not declared the items attribute which is required, this must be any kind of collection or an array of beans that you want to output. Also you do not need that begin/end/step in your example because as default it begins at 0, ends at the end of the array/collection and steps by 1.



Hope this helps.

Sean
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Mr. Clark, I ll check whether this will work and come back soon.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mr. Clark, that one worked, I have one more doubt, I want the index also, can please tell me how to get the index of each bean.

Thank you in advance. Have a nice day.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the varStatus attribute of the forEach tag.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Christophe, I want to do like this

Is there any way?
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For now I declared another method in the bean, called setIndex(byte index)

Then I am getting the index in the jsp as ${bean.index}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic