2
liferay에 하나의 포틀릿을 작성했습니다 (이것은 내 첫 포틀릿입니다). 나는 lifecay의 mvc 구조를 따라 갔다. 자바 다음과 같이의 파일 : -을 View.jsp에서 아약스를 사용liferay 포틀릿의 Ajax
package com.liferay.samples;
import java.io.IOException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletPreferences;
//import javax.portlet.GenericPortlet;
import com.liferay.util.bridges.mvc.MVCPortlet;
public class MyGreetingPortlet extends MVCPortlet {
@Override
public void processAction(
ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
PortletPreferences prefs = actionRequest.getPreferences();
String greetingname = actionRequest.getParameter("greetingname");
String greeting = actionRequest.getParameter("greeting");
if (greeting != null && greetingname != null)
{
prefs.setValue(greetingname, greeting);
prefs.store();
}
//System.out.println("In doView code");
super.processAction(actionRequest, actionResponse);
}
public void fetchdataAction(ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
System.out.println("In doView code");
//super.fetchdataAction(actionRequest, actionResponse);
}
}
하지만 fetchdataAction를 호출 할 때()는 아무 것도 반환하지 않습니다 파일. 다음과 같이 을 View.jsp 파일 : -
<%@ 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>
당신이 나에게 큰 도움이 될 것 나를 도울 수 있다면
.
안녕 Stackfish, 나는 일은 있지만, 다른 방법으로 같은 종류의 일을하고 싶습니다. 나는 2 개의 포틀릿을 가지고있다. 1) 검색 및 2) 검색 결과 표시 AJAX 호출없이 성공적으로 완료되었습니다. 이제 저는 Ajax를 사용하고 싶습니다. 이걸 어떻게 할 수 있니? 나는이를 위해 Inter Portlet Communication (IPC) 메커니즘을 사용하고있다. 친절하게 나를 이끄십시오. 나는 이렇게 오래 동안 고투하고있다 .... 감사합니다. – Scorpion