This wiki does not contain official documentation and is currently deprecated and read only. Please try reading the documentation on the Liferay Developer Network, the new site dedicated to Liferay documentation. DISCOVER Build your web site, collaborate with your colleagues, manage your content, and more. DEVELOP Build applications that run inside Liferay, extend the features provided out of the box with Liferay's APIs. DISTRIBUTE Let the world know about your app by publishing it in Liferay's marketplace. PARTICIPATE Become a part of Liferay's community, meet other Liferay users, and get involved in the open source project. « Retour - 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>
59669 vues