• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing formbean

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The airline is called "Virgin"? Don't you want a plane to go all the way? This tiny ad will go all the way:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic