Form Entries API
Controller Class
============
render(){
String dataIs = getData(); //make your changes
try {
long formInstanceId = 56685;
List<DDMFormInstanceRecord> ddmFormInstanceRecord = DDMFormInstanceRecordLocalServiceUtil.getFormInstanceRecords(formInstanceId);
List<CustomerInformation> customerInfo = new ArrayList<CustomerInformation>();
for (DDMFormInstanceRecord ddmFormInstanceRecord2 : ddmFormInstanceRecord) {
LOG.info("============== DDM Instance Record ================== "+ddmFormInstanceRecord2.getFormInstanceRecordId());
CustomerInformation customerObj = new CustomerInformation();
JSONObject locObj = JSONFactoryUtil.createJSONObject(dataIs);
JSONObject obj1 = JSONFactoryUtil.createJSONObject(locObj.getString("Text01534184"));
String locationValues = obj1.getString("values");
JSONArray locationArray = JSONFactoryUtil.createJSONArray(locationValues);
for (int x=0;x<locationArray.length();x++) {
JSONObject locaInf = JSONFactoryUtil.createJSONObject(locationArray.getString(x));
if(Long.parseLong(locaInf.getString("formInstanceRecordId")) ==ddmFormInstanceRecord2.getFormInstanceRecordId()) {
LOG.info(ddmFormInstanceRecord2.getFormInstanceRecordId() + " locaInf::::::: "+locaInf.getString("formInstanceRecordId")+" Name:: "+locaInf.getString("value"));
customerObj.setCustomerLocation(locaInf.getString("value"));
}
}
JSONObject phoneObj = JSONFactoryUtil.createJSONObject(locObj.getString("Text94393221"));
String phoneValues = phoneObj.getString("values");
JSONArray phoneArray = JSONFactoryUtil.createJSONArray(phoneValues);
for (int x=0;x<phoneArray.length();x++) {
JSONObject phoneInf = JSONFactoryUtil.createJSONObject(phoneArray.getString(x));
if(Long.parseLong(phoneInf.getString("formInstanceRecordId")) ==ddmFormInstanceRecord2.getFormInstanceRecordId()) {
LOG.info(ddmFormInstanceRecord2.getFormInstanceRecordId() + " Phone::::::: "+phoneInf.getString("formInstanceRecordId")+" val:: "+phoneInf.getString("value"));
customerObj.setPhoneNumber(phoneInf.getString("value"));
}
}
JSONObject custNameObj = JSONFactoryUtil.createJSONObject(locObj.getString("Text66962576"));
String custNameValues = custNameObj.getString("values");
JSONArray custNameArray = JSONFactoryUtil.createJSONArray(custNameValues);
for (int x=0;x<custNameArray.length();x++) {
JSONObject custNameInf = JSONFactoryUtil.createJSONObject(custNameArray.getString(x));
if(Long.parseLong(custNameInf.getString("formInstanceRecordId")) ==ddmFormInstanceRecord2.getFormInstanceRecordId()) {
LOG.info(ddmFormInstanceRecord2.getFormInstanceRecordId() + " custNameInf::::::: "+custNameInf.getString("formInstanceRecordId")+" custNameInfName:: "+custNameInf.getString("value"));
customerObj.setCustomerName(custNameInf.getString("value"));
}
}
JSONObject emailObj = JSONFactoryUtil.createJSONObject(locObj.getString("Text61517584"));
String emailObjValues = emailObj.getString("values");
JSONArray emailObjValuesArray = JSONFactoryUtil.createJSONArray(emailObjValues);
for (int x=0;x<emailObjValuesArray.length();x++) {
JSONObject emailInf = JSONFactoryUtil.createJSONObject(emailObjValuesArray.getString(x));
if(Long.parseLong(emailInf.getString("formInstanceRecordId")) ==ddmFormInstanceRecord2.getFormInstanceRecordId()) {
customerObj.setCustomerEmail(emailInf.getString("value"));
LOG.info(ddmFormInstanceRecord2.getFormInstanceRecordId() + " emailInf::::::: "+emailInf.getString("formInstanceRecordId")+" emailInfBValue:: "+emailInf.getString("value"));
}
}
customerInfo.add(customerObj);
LOG.info("============== DDM End ================== ");
}
LOG.info("============== customerInfo ================== "+customerInfo);
renderRequest.setAttribute("customerInfo", customerInfo);
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
Create One Util Class
package com.exo.util;
public class CustomerInformation {
String customerName;
String customerEmail;
String phoneNumber;
String customerLocation;
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getCustomerEmail() {
return customerEmail;
}
public void setCustomerEmail(String customerEmail) {
this.customerEmail = customerEmail;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getCustomerLocation() {
return customerLocation;
}
public void setCustomerLocation(String customerLocation) {
this.customerLocation = customerLocation;
}
}
view.jsp:
<%@page import="com.exo.util.CustomerInformation"%>
<%@page import="java.util.List"%>
<%
List<CustomerInformation> allCustomerInfo = (List<CustomerInformation>)request.getAttribute("customerInfo");
%>
<table>
<tr> <th>Customer Name</th> <th>Address</th> <th>Email id</th> <th>Contact No</th>
</tr>
<%for(CustomerInformation customerDetails: allCustomerInfo){ %>
<tr>
<td><%=customerDetails.getCustomerName() %></td>
<td><%=customerDetails.getCustomerLocation() %></td>
<td><%=customerDetails.getCustomerEmail() %></td>
<td><%=customerDetails.getPhoneNumber() %></td>
</tr>
<%} %>
</table>