You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Mike R. Phelan" <mr...@vsticorp.com> on 2004/01/17 21:11:02 UTC

reference non-String/"complex" JavaBean attributes via struts-bean tag library?

Hi all,

Is there a way to directly reference a complex Object attribute within a JavaBean on a JSP via the struts-bean tag library?

I have had good luck placing ArrayList objects in the HttpSession, then referencing them in a JSP:

Action subclass excerpt:
session.setAttribute("projects", projectsArrayList);

JSP excerpt:
<logic:present scope="session" name="projects">
...
  <logic:iterate id="project" name="projects">
...
    <bean:write name="project" property="name">
    <bean:write name="project" property="lastModificationDate">
...
  </logic:iterate>
...
</logic:present>

However, I would like to reference an ArrayList that exists within the projectsArrayList object. I was hoping that perhaps I could do something like this:

fantasy JSP excerpt:
<logic:present scope="session" name="projects">
...
  <logic:iterate id="project" name="projects">
...
    <bean:write name="project" property="name">
    <bean:write name="project" property="lastModificationDate">
...
  </logic:iterate>
...
<logic:iterate id="teamMember" name="projects.teamMembers"> <!--FANTASY PART-->
...
  <bean:write name="teamMember" property="firstName"> <!--FANTASY PART-->
  <bean:write name="teamMember" property="lastName"> <!--FANTASY PART-->
...
</logic:iterate> <!--NEW PART-->
</logic:present>

Or, even better, with nested iterators:
<logic:present scope="session" name="projects">
...
  <logic:iterate id="project" name="projects">
...
    <bean:write name="project" property="name">
    <bean:write name="project" property="lastModificationDate">
...
    <logic:iterate id="teamMember" name="projects.teamMembers"> <!--FANTASY PART-->
...
      <bean:write name="teamMember" property="firstName"> <!--FANTASY PART-->
      <bean:write name="teamMember" property="lastName"> <!--FANTASY PART-->
...
    </logic:iterate> <!--FANTASY PART-->
...
  </logic:iterate>
</logic:present>

I currently get around this by placing two different Objects into the HttpSession, then referencing them separately. This workaround is limiting me for newer functionality, as I need something that keeps the class heirarchy intact.

Is there a way to do this? When I try to use "dot referencing" (projects.TeamMembers), I get nothing rendered on the JSP page. Am I mangling the reference to a sub-object in the struts-bean tag library? Is the fantasy code above actually valid?

Thanks in advance for any help.

Mike Phelan


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org