Wednesday, 19 August 2020

Ajax In Liferay DXP [Ajax with jQuery in Liferay 7]

 Hi All,

Greetings of the day!

Today we will learn how to integrate jQuery in Liferay DXP and will also develop examples for the same.

Below is what we will achieve at the end of the example.

After entering the pin code and clicking on Fetch Address we will add an ajax call and fetch state and city as shown below.

So let's start.

First, create an MVC portlet StudentMgt, if you need any help on this please refer to my post Create liferay mvc portlet.

Below is the project structure for reference.

Now create Address.java class under respective package shown above,

Currently, we are not integrating our portlet with the database we will create a Util class with static data for the current example.So create StudentUtil.java

Now let's add serverResourse method in the Portlet class which will handle ajax calls, here we will fetch the received pin code pass in ajax code from jquery.

After we receive the pin code, we will call over util class to find the address based on the pin code, you can integrate the database by using service builder, if you need guidance on service builder and retrieving data from the database refer to my posts Service Builder In Liferay DXP & CRUD in Liferay DXP.

So below is serverResourse method for reference

Now the final step is to create portlet:resourceURL in our view.jsp and add Html code to generate fields. Also we are including jquery js and other jquery code in view.jsp [You can create js file in META-INF/resources/js folder and add  ajax code and include it in jsp ]

Now we have completed our code, just build and deploy the portlet after that place the portlet on some page and use it.

If you have any questions please feel free to ask.

Another related post 

CRUD Using Ajax jQuery In Liferay DXP  

If you need help in deploying portlet in Liferay dxp refer to my post Deploy portlet in liferay dxp 

For Spring boot, Spring microservices, Spring MVC, Spring Batch, Hibernate refer 

For Java - Java 8 refer to Java Tutorial

Backlink To Festival Images

Thank You

Happy Leaning.



 




  






 





3 comments:

  1. I copy and paste same code in my liferay dxp 7.3.1 version, it is not working, when I entered pincode not fetching any details.

    ReplyDelete