views:

126

answers:

2

Hi,

I am trying to create a table to display some data I pulled out from a database into a JSP page (all part of a Struts2 application), and I don't know what I'm doing wrong here...

This is the part of my JSP page where I create the table:

<table>
 <s:iterator value="table" id="row">
        <tr>
         <s:iterator value="row" id="cell">
                <td><s:property /></td>
            </s:iterator>
        </tr>
    </s:iterator>
</table>

I have an ArrayList<ArrayList<String>> named table in my action class, and I'm pretty sure I have it populated with the correct values. I'm sure this is some easy syntactical error, but I'm still a beginner to Struts2.

+1  A: 

might need # character added:

do a test to see if your table value is returning anything:

<table>
 <s:iterator value="%{table}" id="row">
        <tr>
         <s:iterator value="%{#row}" id="cell">
                <td><s:property value="%{#cell}"/></td>
            </s:iterator>
        </tr>
    </s:iterator>
</table>
stage
The table still isn't showing up... Is there anything I need to do to make sure my Struts elements show up correctly (for example, I had to return the constant NONE to get some of my other pages to show up previously)?
Raymond Chang
Also, this might help: When I look at the source code for the generated HTML page (where I am trying to display the table at), I only see a <table> tag, then a closing </table> tag with nothing inside.
Raymond Chang
made an adjustment to sample - let me know if that works
stage
It still doesn't work... I think something might be wrong with my getter and setter for table. I tried putting this in my JSP page:<s:if test="%{table}.isEmpty()"> TABLE IS EMPTY </s:if> <s:else> TABLE IS NOT EMPTY </s:else>And my page prints out "TABLE IS NOT EMPTY". However, nothing prints out when I use the tag <s.property value="table">, and nothing in the table prints.
Raymond Chang
A: 

I took your JSP code, and wrote a getter in an action like this, using your JSP, it worked fine. Your JSP code is fine. There appears to be something wrong with your getter method or the population of the 'table'. If you post that, maybe we can figure out what's wrong with it.

public String execute()
{
    m_arrayList = new ArrayList< ArrayList< String > >();
    for( int i = 0; i < 10; ++i ) {
        ArrayList< String > strs = new ArrayList< String >();

        for( int j = i; j < 10 + i; ++j ) {
            strs.add( Integer.toString( j ) );
        }

        m_arrayList.add( strs );
    }

    return SUCCESS;
}

private ArrayList< ArrayList< String > > m_arrayList;

public ArrayList< ArrayList< String > > getTable()
{
    return m_arrayList;
}
Shawn D.