I actually tried to solve the problem by using OGNL.

<s:iterator value="myGroups">
    Group name: <s:property value="name"/>
    Size: <s:property value='members.size()'/> members
</s:iterator> 

In my second attempt, I called a non-property method:

In JSP:
...
    Size: <s:property value='membersSize()'/> members
...
In POJO:
        @Transient
        public int getMembersSize() {
                return members.size();
        }


In both cases I ended up with a LazyInitializationException.

[seepo] ERROR [btpool0-1] LazyInitializationException.<init>(19) | failed to
lazily initialize a collection of role: org.seepo.model.Group.members, no
session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a
collection of role: org.seepo.model.Group.members, no session or session was
closed


Any idea? Your link to the page which describes JSTL functions says that
these functions are for String manipulations. I did not try it, but I guess,
they won't work with collections, will they?

Martin



mraible wrote:
> 
> You should be able to get members.size() if you use OGNL and a
> <s:property> tag. You can also use JSTL functions and the "length"
> function.
> 
> http://java.sun.com/j2ee/1.4/docs/tutorial-update2/doc/JSTL8.html
> 
> Matt
> 
> On Mon, Apr 28, 2008 at 9:16 AM, Martin Homik <[EMAIL PROTECTED]> wrote:
>>
>>  Problem:
>>   * I have a "Group" POJO which keeps a list of its "members" (ManyToMany
>>  relation).
>>   * The GroupAction class stores a list of my current groups and it has a
>>  group field for
>>      accessing information of a single group. In principle, the stucture
>> is
>>  very similar to the
>>      PersonAction of the online tutorial.
>>
>>  Question: In the JSP, I iterate through the groups and print some group
>>  information. For each group, I'd like to print the number of members.
>> How do
>>  I get it?  Can I access somehow members.size() in the JSP? Or am I on a
>>  completely wrong path?
>>
>>  Note: I tried a few things by try-and-error and sometimes I ended up
>> with a
>>  Hibernate LazyInitializationException. Now, I just don't know at what
>> end to
>>  continue? Is it something that
>>  i) can be solved simply via JSP and some expression, or
>>  ii) do I have to do something in the Action class, or
>>  iii) does it go further down into the persistence layer?
>>
>>  Hope, my mail is not too short and you understand my problem.
>>  --
>>  View this message in context:
>> http://www.nabble.com/How-to-access-collection-fields-in-Struts2--tp16941170s2369p16941170.html
>>  Sent from the AppFuse - User mailing list archive at Nabble.com.
>>
>>
>>  ---------------------------------------------------------------------
>>  To unsubscribe, e-mail: [EMAIL PROTECTED]
>>  For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-access-collection-fields-in-Struts2--tp16941170s2369p16944803.html
Sent from the AppFuse - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to