my dog learned polymorphism*
The moose likes JSP and the fly likes How to use array of beans in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to use array of beans in jsp" Watch "How to use array of beans in jsp" New topic
Author

How to use array of beans in jsp

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

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: 60739
    
  65

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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

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: 800

Thank you Mr. Clark, I ll check whether this will work and come back soon.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

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: 14687
    
  16

Check the varStatus attribute of the forEach tag.


[My Blog]
All roads lead to JavaRanch
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Hi Christophe, I want to do like this

Is there any way?
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

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}
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to use array of beans in jsp
 
Similar Threads
JSTL forEach
Converting request parameters to JSP tag-file attributes
JSTL choose not executing as expected
How to retain formatting when passing a String to a JSP
web container displaying jsp intead of html