Results 1 to 3 of 3
  1. #1
    Adrenaline is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Unhappy Nested List not loaded by struts?

    Hi,

    Issue
    When I try to get a list within an object that is part of another list, it is null on the JSP.

    Here's my basic architecture:

    Java Backend:
    Class SomeAction {
    List<Reports> reports;

    //appropriate setters and getters
    ...
    }

    Class Reports {
    List<Parameters> parameters;

    //appropriate setters and getters
    ...
    }

    JSP:
    <s:if test="reports!=null && reports.size() > 0">
    <s:iterator id="reports" value="reports" status="stat"
    Test Message <s: property value='#stat.index' />
    <s:if test="reports[%{#stat.index}].parameters!=null">
    We have a Parameter
    <s:iterator id="reportParameters" value="reportParameters" status="paramStat">
    Parameter Test Message SUCCESS <s: property value='#paramStat.index' />

    </s:iterator>
    </s:if>
    <s:else>
    Parameter List is NULL!
    </s:else>


    </div>
    </s:iterator>
    </s:if>

    Output
    Test Message 0 Parameter List is NULL!
    Test Message 1 Parameter List is NULL!

    Summary
    So, it's failing at the if statement because it seems like the JSP is not getting the nested parameter list. I've double-checked that the parameters list is valid and is not null when I break in the java code.

    I'm pretty new to JSPs, so any help would be appreciated!

    Thank You!
    Last edited by Adrenaline; 05-14-2011 at 03:14 AM.

  2. #2
    Adrenaline is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default [Resolved]

    My friend has provided me with this solution if anyone is interested.

    if test condition was not correct and while iterating over the reports parameter property the object referred in value attribute was not correct.
    Please use the following JSP code snippet:
    Java Code:
    <s:if test="reports!=null && reports.size() > 0">
                <s:iterator id="reports" value="reports" status="stat">
                   Test Message <s:property value='#stat.index' />
                            <s:if test="reports[#stat.index].parameters!=null">
                                We have a Parameter 
                                       <s:iterator value="reports[#stat.index].parameters" status="paramStat">
                                                     Parameter Test Message SUCCESS  <s: property value='#paramStat.index' />
                                        </s:iterator>
                            </s:if>
                            <s:else>
                                 Parameter  List is NULL! 
                            </s:else>
                </s:iterator>
    </s:if>
    
    Or you can use the following simplified version:
    
    <s:if test="reports!=null && reports.size() > 0">
                <s:iterator id="reports" value="reports" status="stat">
                   Test Message <s:property value='#stat.index' />
                                   <s:if test="{parameters != null}">
                                         We have a Parameter <br />
                                        <s:iterator value="parameters" status="paramStat">
                                                          Parameter Test Message SUCCESS <s:property value='#paramStat.index' />, value = 
                                                    <s:property value='testStr' /><br />
                                        </s:iterator>
                            </s:if>
                            <s:else>
                                         Parameter  List is NULL! 
                             </s:else>
                </s:iterator>
    </s:if>

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

Similar Threads

  1. Replies: 1
    Last Post: 07-27-2010, 09:04 AM
  2. Nested List class for Simulation Queue
    By Cheddz in forum Advanced Java
    Replies: 2
    Last Post: 02-19-2010, 01:19 AM
  3. nested collapsing list
    By roohja in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 01-05-2009, 07:15 AM
  4. validating selection list in struts!
    By rameshraj in forum Web Frameworks
    Replies: 2
    Last Post: 02-13-2008, 01:21 PM
  5. foreach in jstl to display nested colums-struts jsp
    By adil7 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 02-11-2008, 06:19 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •