Raymond Chang
Raymond Chang

Reputation: 23

Trying to create a table in Struts2 from an ArrayList

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.

Upvotes: 0

Views: 8890

Answers (2)

Shawn D.
Shawn D.

Reputation: 8135

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;
}

Upvotes: 0

Darin Howard
Darin Howard

Reputation: 397

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>

Upvotes: 1

Related Questions