| Author |
How to use array of beans in jsp
|
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
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.
|
Love all, trust a few, do wrong to none.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56179
|
|
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?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
|
Oops, I am sorry, its not a request parameter, its a request attribute actually.
|
 |
Sean Clark
Rancher
Joined: Jul 15, 2009
Posts: 377
|
|
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
|
I love this place!
|
 |
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
|
Thank you Mr. Clark, I ll check whether this will work and come back soon.
|
 |
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
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
Joined: Nov 24, 2005
Posts: 14672
|
|
|
Check the varStatus attribute of the forEach tag.
|
[My Blog]
All roads lead to JavaRanch
|
 |
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
Hi Christophe, I want to do like this
Is there any way?
|
 |
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
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}
|
 |
 |
|
|
subject: How to use array of beans in jsp
|
|
|