Liferay is a Gartner Magic Quadrant Leader for the Sixth Year! Find out why

Forums

Home » Alloy UI » English

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Arko Mahmud
Ajax sample Portlet
July 19, 2013 2:59 AM
Answer

Arko Mahmud

Rank: Junior Member

Posts: 43

Join Date: June 11, 2013

Recent Posts

Hi
I am searching for a sample portlet that do ajax request and get jason response.
In this way, portlet get Data from database.
I could not find any complete sample project on it.
venkey j jonnakuti
RE: Ajax sample Portlet
July 19, 2013 3:26 AM
Answer

venkey j jonnakuti

Rank: New Member

Posts: 3

Join Date: June 28, 2013

Recent Posts

hi


i want the same
please post
Arko Mahmud
RE: Ajax sample Portlet
July 19, 2013 3:45 AM
Answer

Arko Mahmud

Rank: Junior Member

Posts: 43

Join Date: June 11, 2013

Recent Posts

For Example I have a class

Person with attributes personID, personWeight, personTemperature and datetime. Stored in Database.

I want to do ajax call by PersonID to see his weight or Temperature graph for particular timeline. All I know, I can call list from Database to controller But I don't know How can I convert it to jason obejct and forward it to JSP upon request, so that JSP won't refresh the page but display new graph.
subhash lamba
RE: Ajax sample Portlet
July 19, 2013 8:41 AM
Answer

subhash lamba

Rank: Regular Member

Posts: 136

Join Date: July 7, 2013

Recent Posts

step 1: create resource url
<portlet:resourceURL var="getPlan" id="getPlan" ></portlet:resourceURL>

step 2:
var planId=1;
$.ajax({
dataType: "json",
url:"<%= getPlan %>",
data:{planId:planId},
success:function(data)
{

$("#planDescription").html(data['description']);
$("#planName").html(data['planName']);
$("#planId").val(data['planId']);

........ your code ........
}
});

step 3:
@ResourceMapping(value="getPlan")
@ResponseBody
public void getPlan(ResourceRequest request,ResourceResponse response) throws PortalException, SystemException, IOException
{

long planId=Long.parseLong(request.getParameter("planId"));
plan planData= planLocalServiceUtil.getplan(planId);


JSONObject json = JSONFactoryUtil.createJSONObject();
json.put("description", planData.getPlanDescription());
json.put("planName", planData.getPlanTitle());
json.put("planPrice", planData.getPlanPrice());
json.put("planId", planData.getPlanId());


System.out.println(json.toString());
response.getWriter().write(json.toString());

}
I am using jquery and spring-mvc. I hop this will helpfull to u. if any problem you may ask. i will help you..
Arko Mahmud
RE: Ajax sample Portlet
July 24, 2013 2:06 AM
Answer

Arko Mahmud

Rank: Junior Member

Posts: 43

Join Date: June 11, 2013

Recent Posts

Hi
Thanks for your answer. I made the program using Liferay IDE and serveresouce method.

I just have a question. If you use Spring MVC, Can you use service builder ? or you write down all model, service and DAO classes ?

Thanks in advance !
subhash lamba
RE: Ajax sample Portlet
July 24, 2013 6:13 AM
Answer

subhash lamba

Rank: Regular Member

Posts: 136

Join Date: July 7, 2013

Recent Posts

yes i am using spring mvc and also using service builder.
but what u wont actual?
why you wont to class name?
Arko Mahmud
RE: Ajax sample Portlet
July 24, 2013 7:01 AM
Answer

Arko Mahmud

Rank: Junior Member

Posts: 43

Join Date: June 11, 2013

Recent Posts

Well I am asking because i was trying to make the portlet using Spring MVC, but moved to Liferay IDE as found it easier. As I am new in this area. I don't know which way is better. Spring MVC or Liferay IDE.
Thanks
subhash lamba
RE: Ajax sample Portlet
July 24, 2013 8:47 PM
Answer

subhash lamba

Rank: Regular Member

Posts: 136

Join Date: July 7, 2013

Recent Posts

you question about Ajax. not about spring mvc or liferay IDE. sorry
sheela mk
RE: Ajax sample Portlet
July 25, 2013 2:54 AM
Answer

sheela mk

Rank: Regular Member

Posts: 111

Join Date: February 16, 2012

Recent Posts

Hai..Arko..

Regarding Spring MVC..

You can check this link..
Its Good Article


Link

Thanks and Regards,
Sheela