
« Back to 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>
59153 Views