Struts: Beans inside Beans

Bean inside Bean inside Bean

public class UniversityDetails implements Serializable {
	private ArrayList outerArr;// contains SchoolDetails objects
	private int deanName;
	private int location;
	// setters and getters for instance variables


public class SchoolDetails {
	private ArrayList innerArr;// contains StudentDetails objects
	private String schoolName;
	private int totalCount;
	// setters and getters for instance variables


public class StudentDetails {
	private String age;
	private String sex;
	private int height;
	// setters and getters for instance variables
<table>
    <logic:iterate id="SchoolDetails" name="UniversityDetails"
        property="outerArr">
        <tr>
            <td><font size=2><nested:write name="SchoolDetails"
                        property="schoolName" />
            </font>
            </td>
            <td><font size=2> </font>
            </td>
            <td><font size=2> </font>
            </td>
            <td><font size=2> </font>
            </td>
        </tr>
        <nested:iterate id="StudentDetails" name="SchoolDetails"
            property="innerArr">
            <tr>
                <td><font size=2> </font>
                </td>
                <td><font size=2><nested:write name="StudentDetails"
                            property="age" />
                </font>
                </td>
                <td><font size=2><nested:write name="StudentDetails"
                            property="sex" />
                </font>
                </td>
                <td><font size=2><nested:write name="StudentDetails"
                            property="height" />
                </font>
                </td>
            </tr>
        </nested:iterate>
        <tr>
            <td><font size=2> </font>
            </td>
            <td><font size=2> </font>
            </td>
            <td><font size=2> </font>
            </td>
            <td><font size=2><nested:write name="SchoolDetails"
                        property="totalCount" />
            </font>
            </td>
        </tr>
    </logic:iterate>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td><font size=2><bean:write name="UniversityDetails"
                    property="deanName" />
        </font>
        </td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td><font size=2><bean:write name="UniversityDetails"
                    property="location" />
        </font>
        </td>
    </tr>
</table>

Bean inside Bean

public class SchoolDetails implements Serializable {
	private String schoolName;
	private String totalCount;
	private ArrayList classes = new ArrayList();// contains ClassDetails objects
	// setters and getters for the above instance variables
}

public class ClassDetails {
	private int srNumber;
	private String standard;
	private String classteacher;
	private String noOfStudents;
	// setters and getters for the above instance variables
}

<table>
    <logic:iterate id="ClassDetails" name="SchoolDetails"
        property="classes">
        <tr>
            <td><font size=2><nested:write name="ClassDetails"
                        property="srNumber" />
            </font>
            </td>
            <td><font size=2><nested:write name="ClassDetails"
                        property="standard" />
            </font>
            </td>
            <td><font size=2><nested:write name="ClassDetails"
                        property="classteacher" />
            </font>
            </td>
            <td><font size=2><nested:write name="ClassDetails"
                        property="noOfStudents" />
            </font>
            </td>
        </tr>
    </logic:iterate>
    <tr>
        <td></td>
        <td></td>
        <td><font size=2><bean:write name="SchoolDetails"
                    property="schoolName" />
        </font>
        </td>
        <td><font size=2><bean:write name="SchoolDetails"
                    property="totalCount" />
        </font>
        </td>
    </tr>
</table>

About cuppajavamattiz
Matty Jacob - Avid technical blogger with interests in J2EE, Web Application Servers, Web frameworks, Open source libraries, Relational Databases, Web Services, Source control repositories, ETL, IDE Tools and related technologies.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: