Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

To Display the Counts of a Collection that is Defined in a Form

 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to display 'counts' in a Collection. And I use JSP scriptlet to do it:

The compiler cannot recognize the Collection 'businessCollection'. It is because businessCollection is defined in the ActivityForm.java.

When I tested whether businessCollection is empty or not, I used:

And it was successful.

Then, how do I display the counts of the Collection in this situation?

Thanks in advance.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use a bean in a scriptlet, you have to pull it out of the scope in which it resides. Here is an example:

<%= ((com.mycompany.ActivityForm)request.getAttribute("ActivityForm")).getBusinessCollection().size() %>

This assumes ActivityForm is in request scope. If it's in session scope, use request.getSession().getAttribute(...)
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This would probably work as well if you are just displaying the value on the screen:

<bean:write name="ActivityForm" property="businessCollection.size" />

- Brent
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately the above will not work, as the size() method does not follow the javaBean standard. In other words, there is no getSize() method to go allong with a size property.

Fortunately, there is a tag just for getting the size of a collection. The following would work:

<bean:size name="ActivityForm" property="businessCollection"/>
[ March 09, 2006: Message edited by: Merrill Higginson ]
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahh yes...I have wondered if they ever planned on adding methods like getSize() and getIterator().

- Brent
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic