« 返回到 AJAX

Ajax in Liferay 5

Form submission #

As of Liferay 5 , form submission is done using JQuery and the LiferayWindowState.EXCLUSIVE window state , that will return just the HTML snippet produced by the portlet.

The following code sample demonstrates the pattern of progressive enhancement where the form will submit without Javascript as well as with (To work with less capable devices .etc.

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="com.liferay.portal.kernel.portlet.LiferayWindowState" %>

<div id="<portlet:namespace />lgoUsers">
<script type="text/javascript">
jQuery(function($){

var <portlet:namespace/>form = $('#'+'<portlet:namespace />fm');

<portlet:namespace/>form.bind("submit",function(event){
	   event.preventDefault();
	   var inputs = $("input, textarea, select", <portlet:namespace/>form);
	   var url = '<portlet:actionURL windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>"/>' + "&" + inputs.serialize(); // see note below
	   $('#<portlet:namespace />lgoUsers').load(url);
});

});
</script>

<form
action="<portlet:actionURL/>"
method="post"
name="<portlet:namespace />fm"
id="<portlet:namespace />fm">

<input name="<portlet:namespace />sn" type="text" value="<c:out value="${sn}"/>" />
<input type="submit" name="<portlet:namespace />sm" value="Search" />
</form>
<ul>
<c:forEach items="${users}" var="user">
	<li><c:out value="${user}"/></li>
</c:forEach>
</ul>
</div>
0 附件
59158 查看
平均 (0 票)
满分为 5,平均得分为 0.0。
评论
讨论主题回复 作者 日期
BUG: jQuery('#'+'<portlet:namespace />fm'); -... Fuad Efendi 2008年11月15日 下午6:39
hi, i've got problem ajax in liferay... delang j 2009年12月2日 下午10:35
What if you have multiple Ajax calls on the... Michael Poznecki 2010年1月4日 下午12:08
FYI, I've posted a demonstration portlet using... Jeff Robinson 2009年7月19日 上午5:38
is there anyway to implement something like... dennis monsewicz 2009年8月4日 下午3:00
Great sample. A little step-by-step... Ilya V. Kalujny 2009年9月14日 上午5:48
Last version of this wiki is unreadable.... Felix Ashirov 2011年11月18日 上午4:57

BUG:
jQuery('#'+'<portlet:namespace />fm');
- called before form is defined in HTML... Quick fix: move javascript block after form definition.
在 08-11-15 下午6:39 发帖。
FYI, I've posted a demonstration portlet using code at the following link:

http://www.robisoft.com/downloads/hello-jquery-portlet/
在 09-7-19 上午5:38 发帖。
is there anyway to implement something like this in PHP?
在 09-8-4 下午3:00 发帖以回复 Jeff Robinson
Great sample. A little step-by-step instructions wont hurt tho emoticon
在 09-9-14 上午5:48 发帖以回复 Jeff Robinson
hi,
i've got problem ajax in liferay
http://www.liferay.com/web/guest/community/forums/-/message_boards/messag­e/4285302

breadcrumb and search form appear twice, any idea to solve this?
在 09-12-2 下午10:35 发帖以回复 Fuad Efendi
What if you have multiple Ajax calls on the same page? How do you make the URL? Would you call multiple backend beans? Or, if you called the same backend bean, how would you handle the logic in the bean?
在 10-1-4 下午12:08 发帖以回复 delang j
Last version of this wiki is unreadable. Version 1.3 looks fine.
在 11-11-18 上午4:57 发帖。