struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anthony Frasso <a...@cornell.edu>
Subject Re: JSP Recursion and the Struts include Tag
Date Sun, 12 Jul 2009 03:25:22 GMT
Thank you for the quick response Avlesh!

Again, I'm somewhat new to Struts, so I'm not sure I understand your
suggestion.  Is there a taglib out there that handles this sort of
thing?  Or are you suggesting writing a custom taglib?

Regards,
Anthony Frasso

On Sat, Jul 11, 2009 at 23:22, Avlesh Singh<avlesh@gmail.com> wrote:
> Never thought of using a taglib?
>
> Cheers
> Avlesh
>
> On Sun, Jul 12, 2009 at 8:49 AM, Anthony Frasso <anf4@cornell.edu> wrote:
>
>> Hello all, and thank you in advance.
>>
>> I'm relatively new to struts 2, as I started working with the
>> framework about 6 months ago on a part time basis.  I'm struggling to
>> solve a problem that I would think would be fairly common: displaying
>> a tree within a JSP.
>>
>> Essentially, I have an object (let's call it "Item") that looks
>> something like the following:
>>
>> class Item {
>>
>>    private String name;
>>    private Set<Item> children;
>>
>>    // getters and setters
>> }
>>
>> Working within a JSP page, I want to display the data within this Item
>> as follows:
>>
>>  <ul>
>>    <li>
>>      <s:property value="item.name"/>
>>      <s:iterator value="item.children" var="child">
>>        <ul>
>>          <li>
>>            <s:property value="child.name"/>
>>            <s:iterator value="child.children" var="grandchild">
>>              <ul>
>>                <li>
>>                  <s:property value="grandchild.name"/>
>>                  <s:iterator value="grandchild.child" var
>> "greatgrandchild">
>>                    ... and so on
>>                  </s:iterator>
>>                </li>
>>              </ul>
>>            </s:iterator>
>>          </li>
>>        </ul>
>>      </s:iterator>
>>    </li>
>>  </ul>
>>
>> Ideally, I would be able to display this data using some sort of
>> recursion, since there's really no way to tell how deep this tree is.
>> If anyone knows of a good solution to this problem, I'd be very
>> interested in hearing it.
>>
>> I did come up with what I thought might be a solution using the
>> <s:include> tag.  I came up with the following:
>>
>> In the main jsp page, I have:
>>
>>  <ul>
>>    <li>
>>      <s:include value="inc/displayItem.jsp">
>>        <s:param name="item" value="item"/>
>>      </s:include>
>>    </li>
>>  </ul>
>>
>> In the included jsp page, I have:
>>
>>  <s:property value="item.name"/>
>>  <s:iterator value="item.children" var="child">
>>    <ul>
>>      <li>
>>        <s:include value="inc/displayItem.jsp">
>>          <s:param name="item" value="child"/>
>>        </s:include>
>>      </li>
>>    </ul>
>>  </s:iterator>
>>
>> This does not work, of course, because a parameter from within an
>> included jsp page can only be referenced like this: {$param.item}.  In
>> addition, I can't use that method to access the included parameter
>> within any struts 2 tags (as far as I can tell).
>>
>> So again, I suppose my question is: is this an appropriate way of
>> solving this problem?  If so, how can I get this all to work?  If not,
>> what's a better way of going about this?
>>
>> Thanks again for all of your help,
>> Anthony Frasso
>> anf4@cornell.edu
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>

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


Mime
View raw message