How to display list data on pop up using struts2

1.2k views Asked by At

I have list of object in my action class as below.

private ArrayList<Employee> emp_list;
public ArrayList<Employee> getEmp_list() {
    return emp_list;
}
public void setEmp_list(ArrayList<Employee> emp_list) {
    this.emp_list = emp_list;
}

Bean Class : (it has getter and setters)

private String name;
private String designation;
private String project;

Now on jsp page I want display this list data to be displayed as table on pop-up on same page on button or href click(showing size of list).

<body>

    <div class="container">
        <h2>Modal Example</h2>
        <!-- Trigger the modal with a button -->
        <table>
            <s:iterator value="emp_list">
                <tr>
                    <td><s:property value="name" /></td>
                    <td>
                        <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Display Details</button>
                    </td>
                </tr>
            </s:iterator>
        </table>

        <!-- Modal -->
        <div class="modal fade" id="myModal" role="dialog">
            <div class="modal-dialog">

                <!-- Modal content-->
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">Employee Details</h4>
                    </div>
                    <div class="modal-body">
                        <table>
                            <tr>
                                <td>Name</td>
                                <td><s:property value="name" />
                                </td>
                            </tr>
                            <tr>
                                <td>Designation</td>
                                <td><s:property value="designation" />
                                </td>
                            </tr>
                            <tr>
                                <td>Project</td>
                                <td><s:property value="project" />
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>

            </div>
        </div>

    </div>

</body>

Please help me out I've stucked here.

1

There are 1 answers

2
nsawaya On

You need to use the <s:iterator> tag in your jsp here you can find an example with struts2 iterator usage with a table.

For the pop-up part, you can use any Html/JS combo (if using bootstrap you can use a modal) and just show or hide your code as needed