I created one portlet in liferay (this is my first portlet). That I followed the mvc structure of liferay. The Java file for it looks like this: -
package com.liferay.samples; import java.io.IOException; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.PortletException; import javax.portlet.PortletPreferences;
But when I call fetchdataAction () using ajax from the view.jsp file, it returns nothing. view.jsp as follows: -
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> <%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %> <%@ page import="java.util.*" %> <%@ page import="javax.portlet.PortletPreferences" %> <portlet:defineObjects /> <div id="ContentGreeting"> This is the <b>Thired Test</b> portlet. <% PortletPreferences prefs = renderRequest.getPreferences(); //forEachPreference //String em[] = String[2]; //em = prefs.getValues(); Enumeration em = prefs.getNames(); //ArrayList aList = Collections.list(em); //out.println("value :-"+ aList.get(1)); String[] greeting = new String[3]; int i=0; while(em.hasMoreElements()) { String key = (String)em.nextElement(); greeting[i] = (String)prefs.getValue( key, "Hello! Welcome to our portal."); //out.println("<br> value :"+greeting); %> <p id='id<%= i %>' onclick="ajaxcallTofetchpage();"><%= greeting[i] %></p> <portlet:renderURL var="editGreetingURL"> <portlet:param name="jspPage" value="/edit.jsp" /> </portlet:renderURL> <a href="<%= editGreetingURL %>&greetingname=<%= key %>">Edit greeting</a> <% i++; } %> </div> <portlet:renderURL var="addGreetingURL"> <portlet:param name="jspPage" value="/add.jsp" /> </portlet:renderURL> <p><a href="<%= addGreetingURL %>">Add greeting</a></p> <portlet:resourceURL var="fetchdataAction"> <portlet:param name="fetchdataAction" value="/view.jsp" /> </portlet:resourceURL> <script> //$("#id1").hide("slow"); function ajaxcallTofetchpage() { $.ajax({ type: "POST", url: "<%= fetchdataAction %>", data: "name=John", success: function(msg){ alert(msg); } }); } </script>
If you can help me, this will be a big help for me.
amol rajhans
source share