-1

I have problem to send dynamic data which is iterated by struts iterator as an array to struts action class as individual array via ajax call and how to receive in struts action class

Here is my sample code:

struts iterations

<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example3">
    <thead>
    <tr>
    <th><a href="#" id="selectall">Select all</a></th>
    <th>Student Name</th>
    <th>Phone</th>
    <th>Email</th>
    <th>ReferenceId</th>
    </tr>
    </thead>
    <tbody>
    <s:iterator value="adminSms">
    <tr>
    <td><s:checkbox name="refIDS" cssClass="case" fieldValue="%{ref}" /></td>
    <td><s:property value="studentname" /></td>
    <td id="phone"><s:property value="phone" /></td>
    <td id="email"><s:property value="email" /></td>
    <td><s:property value="ref" /></td>
    </tr>
    </s:iterator>
    </tbody>
    </table>

Ajax call

$(document).ready(function() {
            $('Send').click(function() {
                var Data = {
                    phone : $('#phone').val(),
                    email : $('#email').val()
                }
                $.ajax({
                    type : 'POST',
                    url : 'myURL',
                    data : JSON.stringify(Data)
                });
            });
        });

Action class

public class MyActionClass extends ActionSupport {

    private String [] phoneNumbers;
    private String [] emails;

    public String[] getPhoneNumbers() {
        return phoneNumbers;
    }

    public void setPhoneNumbers(String[] phoneNumbers) {
        this.phoneNumbers = phoneNumbers;
    }

    public String[] getEmails() {
        return emails;
    }

    public void setEmails(String[] emails) {
        this.emails = emails;
    }

    @Override
    public String execute() throws Exception {
        for (int i = 0; i < emails.length; i++) {
            System.out.println(emails[i]);
        }
        for (int i = 0; i < phoneNumbers.length; i++) {
            System.out.println(phoneNumbers[i]);
        }
        return SUCCESS;
    }
}
srinivas gowda
  • 486
  • 5
  • 23

1 Answers1

-1

Here in the below code to send two field values i concatenate two field values in fieldValue attribute

<s:iterator value="adminSms">
<tr>
<td><s:checkbox name="emails" cssClass="case" fieldValue="%{phone+'@'+email}" /></td>
<td><s:property value="studentname" /></td>
<td id="phone"><s:property value="phone" /></td>
<td id="email"><s:property value="email" /></td>
<td><s:property value="ref" /></td>
</tr>
</s:iterator>
srinivas gowda
  • 486
  • 5
  • 23