In my struts application - I have a list defined in a formbean - which I show on the JSP - with regular iteration Struts tags.
Now, to be able to layout the list in two columns - I need to know the size of the list before hand.
How can I access this list?
If I somehow could access the list - like;
List list = myFormBean.getList(); int listSize = list.size();
But I get the error myFormBean is unknown. The I could use a useBean tag - but again - I don't get access to the same instance of the bean - as Struts uses.
How do I solve this problem?
Best Regards, Henrik
Joined: Jul 26, 2005
Use a property - say noOfRecords, in your form bean which stores the size of the list. Use a logic tag(logic:greaterThan, logic:lessThan) in your JSP to check the value of the noOfRecords and display your list accordingly.
Joined: Feb 15, 2005
If you want to access a bean in a scripting variable, you must get it from the scope in which it is stored. So, if myFormBean is in request scope, you could access it like this:
List list = ((com.mycompany.MyFormBean)request.getAttribute("myFormBean")).getList(); int listSize = list.size();
Another way to do it would be to use the <bean:size> tag like this: