• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing formbean

 
Henrik Krievs
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy!

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
 
Zip Ped
Ranch Hand
Posts: 336
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

<bean:size id="size" name="myFormBean" property="list" />

This provides you with a page scoped variable named "size" which contains the size of the list in myFormBean.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic