Monday 16 September 2024

 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>

Monday 1 August 2022

 

Inter Portlet Communication (IPC) in Liferay 7.4


Public Render Parameter IPC:

1) Create a new module project -> SenderPortlet

2) In SenderPortlet  add the below property in controller class under component annotation 

    

    "javax.portlet.supported-public-render-parameter=ipcMessage"


3) Based on action, we need to set the parameter in actionResponse object

    @Override

    public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)

throws IOException, PortletException {

    String ipcMessage =ParamUtil.getString(actionRequest, "sendingValue");

    actionResponse.setRenderParameter("ipcMessage", ipcMessage);

    }


4) Create a another module project -> RecieverPortlet


5) In RecieverPortlet add the below property in controller class under component annotation

   

     "javax.portlet.supported-public-render-parameter=ipcMessage"


6) get the value sender value into recieverportlet in render or doview method


        @Override

public void render(RenderRequest renderRequest, RenderResponse renderResponse)

throws IOException, PortletException {

String senderValueIs = ParamUtil.getString(renderRequest, "ipcMessage");

renderRequest.setAttribute("reciveValue"senderValueIs);

super.render(renderRequest, renderResponse);

}


7) Deploy the both portlets


8) Add the portlets into a page in liferay portal



 Form Entries API Controller Class ============ render(){ String dataIs = getData(); //make your changes try { long formIns...