aspose file tools*
The moose likes Struts and the fly likes Accessing formbean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Accessing formbean" Watch "Accessing formbean" New topic
Author

Accessing formbean

Henrik Krievs
Ranch Hand

Joined: Jan 05, 2004
Posts: 59
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

Joined: Jul 26, 2005
Posts: 336
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

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing formbean
 
Similar Threads
How to get the List of populated Beans?
Autopupulate of the jsp page using values from th FormBean
struts
How to "carry" JSP form input over few pages (clicks) down ?
How to migrate from struts 1 to struts2?