quarta-feira, 18 de janeiro de 2012

Liferay: Buscando imagens no Image Gallery

HTML:

<form action="<liferay-portlet:actionURL name="igFind" portletConfiguration="true" />" method="post" name="<portlet:namespace />fm">

<input type="text" name="<portlet:namespace />find" />

<input type="submit" value="Find" />

</form>




Classe Portlet:

import java.util.List;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

import com.liferay.portal.kernel.dao.orm.DynamicQuery;
import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
import com.liferay.portal.kernel.dao.orm.OrderFactoryUtil;
import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
import com.liferay.portlet.imagegallery.model.IGImage;
import com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;

public class NewPortlet extends MVCPortlet {

public void igFind(ActionRequest request, ActionResponse response){

String find = ParamUtil.getString(request, "find");

ClassLoader loader = PortalClassLoaderUtil.getClassLoader();

DynamicQuery query = DynamicQueryFactoryUtil.forClass(IGImage.class, loader)
.add(PropertyFactoryUtil.forName("name").eq(find))
.addOrder(OrderFactoryUtil.asc("name"));

try {
List results = IGImageLocalServiceUtil.dynamicQuery(query, 0, 100);
for(IGImage ig : results){
System.out.println(ig.getName());
}
} catch (SystemException e) {
e.printStackTrace();
}
}
}

Um comentário:

  1. Acrescentar ao código HTML:
    <%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>

    ResponderExcluir