Sathish Kumar k k
Sathish Kumar k k

Reputation: 1842

row wise action in struts2

I am in need to update a table with grade for each employee one by one, the table on jsp page shows some performance data of individual employee in each row along with a struts2 select drop down list in each row and a update anchor tag. Which is created using struts2 iterator tag.

What I need is while I press this update link it should take the selected value from dropdown list and update the current row.

How to achieve this ? I want to know what do I need to do in onClick event for update anchor tag?

Upvotes: 1

Views: 1065

Answers (2)

Sathish Kumar k k
Sathish Kumar k k

Reputation: 1842

I found a solution for my question. In this I generate id dynamically for input in each row of a column, mean while the anchor tag also generated with this element id respectively as a parameter for javascript function inside onclick attribute. So while I click update link it takes the textfield id of this corrosponding row to the javascript function. This makes me to get the value and update it row wise. Here is a example how I did it.

<script type="text/javascript">

        function updateRole(roleID,targetID,id){

            var role = document.getElementById(roleID).value;
            var target = document.getElementById(targetID).value;
            $.ajax({
                url:"updateTeamemploydetails.action",
                data:"testRole="+role + "-" + target + "-" + id,
            }); 

</script>

<table>
            <tr>
                <th >S.No</th>
                <th >Name</th>
                <th >Role</th>
                <th >Target</th>
                <th >Action</th>
            </tr>
                <s:iterator value="emplist" status="empStatus">
            <tr>
                <td ><s:property value="#empStatus.count"/></td>
                <td ><s:property value="empname"/></td>
                <td ><s:textfield name="emprole" id="%{#empStatus.count}" theme="simple"/></td>
                <td ><s:textfield name="target" id="target%{#empStatus.count}" theme="simple"/></td>
                <td ><a href="#" onclick="updateRole('<s:property value="%{#empStatus.count}"/>','target'+'<s:property value="%{#empStatus.count}"/>','<s:property value="empid"/>');" >Update</a></td>
            </tr>
                </s:iterator>
</table>

Upvotes: 0

rai.skumar
rai.skumar

Reputation: 10667

On onclick event call a javascript method. Inside method read all values and then send all these values to server. You can do it using normal form post or Ajax as well.

Upvotes: 0

Related Questions