`

liferay-ui:search-container 标签的使用

 
阅读更多

参考:http://liferaytrends.blogspot.com/2013/01/tabs-with-search-container-in-liferay.html

 

 

想要的效果: 类似liferay 控制面板 搜索User 的页面

可以搜索, 分页, 显示提示信息

1. 

liferay-util:buffer 标签可以把这个标签里面的标签内容当做一个变量赋值给其他标签

<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %> 
<liferay-ui:search-container-column-text
				name="name"
				buffer="buffer"
			>
			
		<liferay-util:buffer var="keywords">
			<liferay-ui:icon-help message="it is  help msg." />
		</liferay-util:buffer>

  

 

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui"%>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> 
  <%@ taglib prefix="liferay-ui" uri="http://liferay.com/tld/ui" %>
  <%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>
  <%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme"%>
  
  <%@page import="com.liferay.portal.theme.ThemeDisplay"%>
   <%@page import="com.liferay.portal.kernel.util.WebKeys"%>
    <%@page import="com.labimo.lesson.portlet.LessonShareMode"%>
      <%@page import="com.labimo.lesson.*"%>
      <%@page import="com.labimo.lesson.service.*"%>
       <%@page import="com.liferay.portal.kernel.util.*"%>
         <%@page import="com.liferay.portal.model.*"%>
          <%@page import="java.util.*"%>
            <%@page import="com.labimo.lesson.model.*"%>
    
    
    
    
    
    
    
    
  
<portlet:defineObjects />
<liferay-theme:defineObjects />

<portlet:actionURL var="editLessonNamePage" name="editLessonNamePage">
</portlet:actionURL>

<portlet:actionURL var="setPasswordPage" name="setPasswordPage">
</portlet:actionURL>

<portlet:actionURL var="deleteLesson" name="deleteLesson">
</portlet:actionURL>

<portlet:actionURL var="setShareModePage" name="setShareModePage">
</portlet:actionURL>


<portlet:actionURL var="replaceLessonPage" name="replaceLessonPage">
</portlet:actionURL>

<portlet:actionURL var="uploadLessonPage" name="uploadLessonPage">
</portlet:actionURL>


<portlet:actionURL var="searchLesson" name="searchLesson">
</portlet:actionURL>


<%-- <aui:form action="<%= uploadLessonPage %>" method="post" name="<portlet:namespace />uploadLessonPage" cssClass="pull-left" >		
	<aui:button name="uploadLessonPage"  type="submit" value="Upload Lesson" />
</aui:form>


<aui:form action="<%= searchLesson %>" method="post" name="<portlet:namespace />searchLesson"  cssClass="pull-right">	
	<aui:row >
	<aui:input name="search"  value="" label="" placeholder="Searech Lesson"></aui:input>
	<aui:button name="uploadLessonPage"  type="submit" value="Search Lesson" cssClass="hidden"/>
	</aui:row >
</aui:form> --%>

<aui:nav-bar>
		<aui:nav>
			<aui:form action="<%= uploadLessonPage %>" method="post" name="<portlet:namespace />uploadLessonPage" cssClass="pull-left" >		
				<aui:button name="uploadLessonPage"  type="submit" value="Upload Lesson" />
			</aui:form>
		</aui:nav>
		
		
		<aui:nav cssClass="pull-right">
			<aui:form action="<%= searchLesson %>" method="post" name="<portlet:namespace />searchLesson"  cssClass="pull-right form-search">	
				<%-- <input name="<portlet:namespace/>search" value=""  placeholder="Searech Lesson"/> --%>
				<%-- <aui:input name="search"  value="" label="" placeholder="Searech Lesson"></aui:input> 
				<aui:button name="uploadLessonPage"  type="submit" value="Search Lesson" cssClass="hidden"/>--%>
				<div id="" class="input-append"> 
					<input type="text" class="search-query span9" name="<portlet:namespace/>search" value="" placeholder="Searech Lesson" title="" id="<portlet:namespace/>search"> 
					<button class="btn" type="submit"> Search </button> 
				</div>
			</aui:form>
		</aui:nav>

	</aui:nav-bar>

<%-- <liferay-ui:search-form>
	<%
	UserSearch searchContainer = (UserSearch)request.getAttribute("liferay-ui:search:searchContainer");
	
	UserDisplayTerms displayTerms = (UserDisplayTerms)searchContainer.getDisplayTerms();
	%>
	
	<liferay-ui:search-toggle
		autoFocus="<%= windowState.equals(WindowState.MAXIMIZED) %>"
		buttonLabel="search"
		displayTerms="<%= displayTerms %>"
		id="toggle_id_users_admin_user_search"
	>
		<aui:fieldset>
			<%@ include file="/html/portlet/directory/user_search_user_name.jspf" %>
	
			<aui:input name="<%= displayTerms.SCREEN_NAME %>" size="20" value="<%= displayTerms.getScreenName() %>" />
	
			<aui:input name="<%= displayTerms.EMAIL_ADDRESS %>" size="20" value="<%= displayTerms.getEmailAddress() %>" />
	
			<c:if test="<%= showActiveUserSelect %>">
				<aui:select name="<%= displayTerms.STATUS %>">
					<aui:option label="any-status" selected="<%= (displayTerms.getStatus() == WorkflowConstants.STATUS_ANY) %>" value="<%= WorkflowConstants.STATUS_ANY %>" />
					<aui:option label="active" selected="<%= (displayTerms.getStatus() == WorkflowConstants.STATUS_APPROVED) %>" value="<%= WorkflowConstants.STATUS_APPROVED %>" />
					<aui:option label="inactive" selected="<%= (displayTerms.getStatus() == WorkflowConstants.STATUS_INACTIVE) %>" value="<%= WorkflowConstants.STATUS_INACTIVE %>" />
				</aui:select>
			</c:if>
		</aui:fieldset>
</liferay-ui:search-toggle>
</liferay-ui:search-form> --%>


<%-- <%
 PortletPreferences prefs = renderRequest.getPreferences();
%> --%>

	<%--<liferay-ui:search-container delta='5' emptyResultsMessage="No lesson , please upload lesson.">
	
		 <liferay-ui:search-container-results
			results="${lessonList}"
			total="${fn:length(lessonList)}"
		/> --%>
		
	<%-- 	<% List<Lesson> lessonList2 = LessonLocalServiceUtil.findByNameOrKeywordsOrDescriptionAndUserId("", "", "", 202, 0, 5) ;
		%> --%>
		
		<liferay-ui:search-container searchContainer="${searchContainer}" >
		
	<%-- 	<liferay-ui:search-form page="<%= searchLesson %>" searchContainer="${searchContainer}" showAddButton="true" >
			<liferay-ui:search-toggle
		buttonLabel="search"
		displayTerms="${searchContainer.displayTerms}"
		id="toggle_id_users_admin_user_search"
	>
		<aui:fieldset>		
			<aui:input name="search" size="20" value="search" />
		</aui:fieldset>
</liferay-ui:search-toggle>
</liferay-ui:search-form> --%>



		 <liferay-ui:search-container-results results="${searchcontainer.results}" total="${searchcontainer.total}"/>
	
		<liferay-ui:search-container-row
			className="com.labimo.lesson.model.Lesson"
			keyProperty="id"
			modelVar="lesson"
		>
		
		<%
		String editLessonNameUrl= editLessonNamePage +  "&" +renderResponse.getNamespace()+"id="+  lesson.getRandomString() + lesson.getId();
		String setPasswordPageUrl= setPasswordPage +  "&" +renderResponse.getNamespace()+"id="+  lesson.getRandomString() + lesson.getId(); 
		String deleteLessonUrl= deleteLesson +  "&" +renderResponse.getNamespace()+"id="+  lesson.getRandomString() + lesson.getId(); 
		String setShareModeUrl= setShareModePage +  "&" +renderResponse.getNamespace()+"id="+  lesson.getRandomString() + lesson.getId();
		String replaceLessonPageUrl= replaceLessonPage +  "&" +renderResponse.getNamespace()+"id="+  lesson.getRandomString() + lesson.getId(); 
		
		//ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
		
		String lessonLink = "http://" + request.getServerName()+"/" +"lesson"+"/ls/"+ lesson.getRandomString() + lesson.getId() +"/player.html"; 
		//String lessonLink = "http://" + request.getServerName()+"/" +"lesson"+"/ls?id="+ lesson.getRandomString() + lesson.getId(); 
		
		String shareMode = LessonShareMode.values()[lesson.getShareMode()].name();
		//lessonLink="<a href='http://www.google.com'>click here</a>";
		%>
		
					
			
				
				
		<liferay-ui:search-container-column-text
				name="name"
				buffer="buffer"
			>
			
		<liferay-util:buffer var="keywords">
			<liferay-ui:icon-help message="${lesson.keywords}" />
		</liferay-util:buffer>
		<liferay-util:buffer var="description">
				<liferay-ui:icon-help message="${lesson.description}" />
		</liferay-util:buffer>
		<liferay-util:buffer var="edit">
				<liferay-ui:icon image="edit" message="RENAME" />
		</liferay-util:buffer>
		<liferay-util:buffer var="add">
				<aui:fieldset helpMessage="add" label="keywords">
				</aui:fieldset>
		</liferay-util:buffer>

		 <%
			 buffer.append(lesson.getName());
			 buffer.append(keywords);
			 buffer.append(description);
			 //buffer.append(edit);
			// buffer.append(add);
		 %>				
			</liferay-ui:search-container-column-text>
		
		
			<liferay-ui:search-container-column-text
				name="lessonLink"
				value="<%=lessonLink %>"
				href="<%=lessonLink %>"
			> </liferay-ui:search-container-column-text>
			
			<%-- <liferay-ui:icon-help message="123"></liferay-ui:icon-help> --%>
			
			<liferay-ui:search-container-column-text
				name="share"
				value="<%=shareMode %>"
			/>
			
			
			
		
			<fmt:formatDate value="${lesson.updateDate}" pattern="yyyy-MM-dd HH:mm:ss" var="updateDate"/>
			<liferay-ui:search-container-column-text
				name="updateDate"
				value="${updateDate}"
			/>
		
	
			<liferay-ui:search-container-column-text
				
			>
		

				<liferay-ui:icon-menu>
					<liferay-ui:icon image="edit" message="EDIT"
						url="<%=editLessonNameUrl %>" />
						<liferay-ui:icon image="edit" message="SHARE"
						url="<%=setShareModeUrl %>" />
								<liferay-ui:icon image="add" message="PASSWORD"
						url="<%=setPasswordPageUrl %>" />
						<liferay-ui:icon image="edit" message="REPLACE"
						url="<%=replaceLessonPageUrl %>" />
						<liferay-ui:icon image="delete" message="DELETE"
						url="<%=deleteLessonUrl %>" />
				
				</liferay-ui:icon-menu>
			
			</liferay-ui:search-container-column-text>
			
	<%-- 	 <liferay-ui:search-container-column-jsp
				
					path="/license_action.jsp"
				/> 
		<c:set var="licenseUuid" scope="request" value="<%=license.getLicenseUuid() %>" />	 --%>
		</liferay-ui:search-container-row>

	<liferay-ui:search-iterator />

</liferay-ui:search-container>

 

2. 把搜索的关键字设置到PortletURL 上面,这样在点击下一页或者前一页的时候, 搜索关键字这个参数的值不会丢失。

  Map<String,String> paramMap= new HashMap<String,String>();
				  paramMap.put("search", search);
		 
		 	/*
			 * Creating IteratorURL and in that we will pass tab parameter
			 */
		        PortletURL iteratorURL= renderResponse.createRenderURL();
				Iterator<Map.Entry<String, String>> entries = paramMap.entrySet().iterator();
				while (entries.hasNext()) {
					Map.Entry<String, String> entry = entries.next();
					iteratorURL.setParameter(entry.getKey(), entry.getValue());
				}

 

package com.labimo.lesson.portlet;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletURL;
import javax.portlet.ProcessAction;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.log4j.Logger;

import com.google.gson.Gson;
import com.labimo.lesson.model.Lesson;
import com.labimo.lesson.model.impl.LessonImpl;
import com.labimo.lesson.service.LessonLocalServiceUtil;
import com.labimo.lesson.service.persistence.LessonUserUtil;
import com.labimo.lesson.service.persistence.LessonUtil;
import com.labimo.lesson.servlet.LaunchLessonServlet;
import com.liferay.portal.kernel.dao.search.SearchContainer;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.FileUtil;
import com.liferay.portal.kernel.util.JavaConstants;
import com.liferay.portal.kernel.util.ListUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.User;
import com.liferay.portal.model.UserGroup;
import com.liferay.portal.service.GroupLocalServiceUtil;
import com.liferay.portal.service.UserGroupLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;

public class LessonPortlet extends MVCPortlet {
		
	private static Logger logger = Logger.getLogger(LessonPortlet.class);
		 
		@Override
		public void doView(RenderRequest renderRequest,
				RenderResponse renderResponse) throws IOException, PortletException {

			String page = (String) renderRequest.getAttribute("page");
			logger.info(" page  =" +  page);
			if(Validator.isNotNull(page)){
				include(page, renderRequest, renderResponse);
			}else{
				try {
					
//					List<Lesson> lessonList = LessonLocalServiceUtil.findByOwnerId(userId);	
//					List<Lesson> lessonList = LessonLocalServiceUtil.findByNameOrKeywordsOrDescriptionAndUserId("", "", "", 202, 0, 5); 
//					renderRequest.setAttribute("lessonList", lessonList);
					searchContainerData(renderRequest,renderResponse);
					
			
				} catch (Exception e) {
					e.printStackTrace();
				}
			
				super.doView(renderRequest, renderResponse);
			}
			
		}
		
		
		@ProcessAction(name = "editLessonNamePage")
		public void editLessonNamePage(ActionRequest actionRequest,
				ActionResponse actionRresponse) {
			
			try {
				logger.info(" page  =  editLessonNamePage" );
				User user = PortalUtil.getUser(actionRequest);
				String lessonIdAndUuid = ParamUtil.getString(actionRequest, "id");
				logger.info(" lessonIdAndUuid  =  " +lessonIdAndUuid);
				if(Validator.isNotNull(user) && Validator.isNotNull(lessonIdAndUuid)){
					long lessonId = Long.valueOf(lessonIdAndUuid.substring(6));
					Lesson lesson = LessonLocalServiceUtil.findByIdAndOwnerId(lessonId, user.getUserId());
					if(Validator.isNotNull(lesson)){
						actionRequest.setAttribute("page", "/editLessonName.jsp");
						actionRequest.setAttribute("lesson" , lesson);
					}
			
				}

			} catch (Exception e) {
				logger.error(e.getMessage());
				e.printStackTrace();
				SessionMessages.add(actionRequest, "error");
			}  
		}
		
		
		@ProcessAction(name = "editLessonName")
		public void editLessonName(ActionRequest actionRequest,
				ActionResponse actionRresponse) {
			
			logger.info("editLessonName");
			try {
				User user = PortalUtil.getUser(actionRequest);
				String lessonIdAndUuid = ParamUtil.getString(actionRequest, "id");
				String lessonName =  ParamUtil.getString(actionRequest, "name");
				String keywords =  ParamUtil.getString(actionRequest, "keywords");
				String description =  ParamUtil.getString(actionRequest, "description");
				
				
				if(Validator.isNotNull(user) && Validator.isNotNull(lessonIdAndUuid) && Validator.isNotNull(lessonName)){
					long lessonId = Long.valueOf(lessonIdAndUuid.substring(6));
					Lesson lesson = LessonLocalServiceUtil.findByIdAndOwnerId(lessonId, user.getUserId());
					if(Validator.isNotNull(lesson)){
						lesson.setName(lessonName);
						lesson.setKeywords(keywords);
						lesson.setDescription(description);
						lesson.setUpdateDate(new Date());
						LessonLocalServiceUtil.updateLesson(lesson);
					}
				
				}

			} catch (Exception e) {
				logger.error(e.getMessage());
				e.printStackTrace();
				SessionMessages.add(actionRequest, "error");
			}  
		}
		
		
		@ProcessAction(name = "setPasswordPage")
		public void setPasswordPage(ActionRequest actionRequest,
				ActionResponse actionRresponse) {
			
			try {
				logger.info(" page  =  setPasswordPage" );
				User user = PortalUtil.getUser(actionRequest);
				String lessonIdAndUuid = ParamUtil.getString(actionRequest, "id");
				logger.info(" lessonIdAndUuid  =  " +lessonIdAndUuid);
				if(Validator.isNotNull(user) && Validator.isNotNull(lessonIdAndUuid)){
					long lessonId = Long.valueOf(lessonIdAndUuid.substring(6));
					Lesson lesson = LessonLocalServiceUtil.findByIdAndOwnerId(lessonId, user.getUserId());
					if(Validator.isNotNull(lesson)){
						actionRequest.setAttribute("page", "/setPassword.jsp");
						actionRequest.setAttribute("lesson" , lesson);
						actionRequest.setAttribute("isProtected" , lesson.isIsProtected());
					}
			
				}
				
			} catch (Exception e) {
				logger.error(e.getMessage());
				e.printStackTrace();
				SessionMessages.add(actionRequest, "error");
			}  
		}
		
		
		@ProcessAction(name = "setPassword")
		public void setPassword(ActionRequest actionRequest,
				ActionResponse actionRresponse) {
			
			logger.info("editLessonName");
			try {
				User user = PortalUtil.getUser(actionRequest);
				String lessonIdAndUuid = ParamUtil.getString(actionRequest, "id");
				String password =  ParamUtil.getString(actionRequest, "password");
				Boolean isProtected = ParamUtil.getBoolean(actionRequest, "isProtected");
				password = EncoderUtil.encodeByMD5(password);
				if(Validator.isNotNull(user) && Validator.isNotNull(lessonIdAndUuid) && Validator.isNotNull(password)){
					long lessonId = Long.valueOf(lessonIdAndUuid.substring(6));
					Lesson lesson = LessonLocalServiceUtil.findByIdAndOwnerId(lessonId, user.getUserId());
					if(Validator.isNotNull(lesson)){
						lesson.setPassword(password);
						lesson.setIsProtected(isProtected);
						lesson.setUpdateDate(new Date());
						LessonLocalServiceUtil.updateLesson(lesson);
					}
				
				}
				
			} catch (Exception e) {
				logger.error(e.getMessage());
				e.printStackTrace();
				SessionMessages.add(actionRequest, "error");
			}  
		}
		
		
		
		@ProcessAction(name = "deleteLesson")
		public void deleteLesson(ActionRequest actionRequest,
				ActionResponse actionRresponse) {
			
			logger.info("delete");
			try {
				User user = PortalUtil.getUser(actionRequest);
				String lessonIdAndUuid = ParamUtil.getString(actionRequest, "id");
				String password =  ParamUtil.getString(actionRequest, "password");
				password = EncoderUtil.encodeByMD5(password);
				if(Validator.isNotNull(user) && Validator.isNotNull(lessonIdAndUuid) && Validator.isNotNull(password)){
					long lessonId = Long.valueOf(lessonIdAndUuid.substring(6));
					Lesson lesson = LessonLocalServiceUtil.findByIdAndOwnerId(lessonId, user.getUserId());
					if(Validator.isNotNull(lesson)){
						LessonLocalServiceUtil.deleteLesson(lesson);
					}	
				}

			} catch (Exception e) {
				logger.error(e.getMessage());
				e.printStackTrace();
				SessionMessages.add(actionRequest, "error");
			}  
		}
		
		
		@ProcessAction(name = "setShareModePage")
		public void setShareModePage(ActionRequest actionRequest,
				ActionResponse actionRresponse) {
			
			try {
				logger.info(" page  =  setShareModePage" );
				User user = PortalUtil.getUser(actionRequest);
				String lessonIdAndUuid = ParamUtil.getString(actionRequest, "id");
				logger.info(" lessonIdAndUuid  =  " +lessonIdAndUuid);
				if(Validator.isNotNull(user) && Validator.isNotNull(lessonIdAndUuid)){
					long lessonId = Long.valueOf(lessonIdAndUuid.substring(6));
					Lesson lesson = LessonLocalServiceUtil.findByIdAndOwnerId(lessonId, user.getUserId());
					if(Validator.isNotNull(lesson)){
						actionRequest.setAttribute("page", "/setShareMode.jsp");
						actionRequest.setAttribute("lesson" , lesson);
						actionRequest.setAttribute("shareMode" , LessonShareMode.values()[lesson.getShareMode()].name());
						List<UserGroup> userGroupList = new ArrayList<UserGroup>();
//						logger.info("for test");
//						logger.info(UserGroupLocalServiceUtil.getUserGroup(user.getCompanyId()).getName());
//						List<UserGroup> userGroupList = UserGroupLocalServiceUtil.getUserUserGroups(user.getUserId());
//						logger.info("for test2");
//						for(UserGroup group : userGroupList){
////							logger.info("for test3");
//							logger.info("group name = " + group.getName());
//						}
						
						List<UserGroup> userGroupList2 = UserGroupLocalServiceUtil.getUserGroups(user.getCompanyId());
//						logger.info("for test2");
						for(UserGroup group : userGroupList2){
//							logger.info("for test3");
							if(group.getName().startsWith("lesson_")){
								userGroupList.add(group);
								logger.info("group name = " + group.getName());
								//TODO:for test
								logger.info("Previlidges " +group.getExpandoBridge().getAttribute("Previlidges"));
								
							}
							
						}
						logger.info("group list = " + userGroupList.toString());
						Gson gson = new Gson();
						actionRequest.setAttribute("userGroupList",  gson.toJson(userGroupList));
					}
			
				}

			} catch (Exception e) {
				logger.error(e.getMessage());
				e.printStackTrace();
				SessionMessages.add(actionRequest, "error");
			}  
		}
		
		
		@ProcessAction(name = "setShareMode")
		public void setShareMode(ActionRequest actionRequest,
				ActionResponse actionRresponse) {
			
			logger.info("setShareMode");
			try {
				User user = PortalUtil.getUser(actionRequest);
				String lessonIdAndUuid = ParamUtil.getString(actionRequest, "id");
				Integer shareMode =  ParamUtil.getInteger(actionRequest, "shareMode");
				Long userGroupId = ParamUtil.getLong(actionRequest, "userGroupId");
				if(Validator.isNotNull(user) && Validator.isNotNull(lessonIdAndUuid) && Validator.isNotNull(shareMode)){
					long lessonId = Long.valueOf(lessonIdAndUuid.substring(6));
					Lesson lesson = LessonLocalServiceUtil.findByIdAndOwnerId(lessonId, user.getUserId());
					if(Validator.isNotNull(lesson)){
						lesson.setShareMode(shareMode);
						lesson.setUpdateDate(new Date());
						if(LessonShareMode.GOURP.ordinal()==shareMode){
							lesson.setUserGroupId(userGroupId);
						}
						LessonLocalServiceUtil.updateLesson(lesson);
					}
				
				}
		
			} catch (Exception e) {
				logger.error(e.getMessage());
				e.printStackTrace();
				SessionMessages.add(actionRequest, "error");
			}  
		}
	
		
		@ProcessAction(name = "replaceLessonPage")
		public void replaceLessonPage(ActionRequest actionRequest,
				ActionResponse actionRresponse) {
			
			try {
				logger.info(" page  =  setShareModePage" );
				User user = PortalUtil.getUser(actionRequest);
				String lessonIdAndUuid = ParamUtil.getString(actionRequest, "id");
				logger.info(" lessonIdAndUuid  =  " +lessonIdAndUuid);
				if(Validator.isNotNull(user) && Validator.isNotNull(lessonIdAndUuid)){
					long lessonId = Long.valueOf(lessonIdAndUuid.substring(6));
					Lesson lesson = LessonLocalServiceUtil.findByIdAndOwnerId(lessonId, user.getUserId());
					if(Validator.isNotNull(lesson)){
						actionRequest.setAttribute("page", "/replaceLesson.jsp");
						actionRequest.setAttribute("lesson" , lesson);
					}
			
				}

			} catch (Exception e) {
				logger.error(e.getMessage());
				e.printStackTrace();
				SessionMessages.add(actionRequest, "error");
			}  
		}
		
		
		@ProcessAction(name = "replaceLesson")
		public void replaceLesson(ActionRequest actionRequest,
				ActionResponse actionRresponse) {
			InputStream ips =null;
			OutputStream ops =null;
			logger.info("replaceLesson");
			try {
				String courseFolder = Utils.getValue("UPLOAD_PATH");
				logger.info("courseFolder=" + courseFolder);
				 
				User user = PortalUtil.getUser(actionRequest);
				UploadPortletRequest uploadRequest =
						 PortalUtil.getUploadPortletRequest(actionRequest);
//				File docFile = uploadRequest.getFile("fileName");
				ips = uploadRequest.getFileAsStream("fileName");
				String lessonName = uploadRequest.getFileName("fileName");
			
				String lessonIdAndUuid = uploadRequest.getParameter("id");
				logger.info("lessonIdAndUuid = " + lessonIdAndUuid);
				if(Validator.isNotNull(user) && Validator.isNotNull(lessonIdAndUuid)){
					long lessonId = Long.valueOf(lessonIdAndUuid.substring(6));
					Lesson lesson = LessonLocalServiceUtil.findByIdAndOwnerId(lessonId, user.getUserId());
					if(Validator.isNotNull(lesson)){
						File file = new File(courseFolder+File.separator + lesson.getOwnerId()+File.separator +lesson.getFolderName());
						logger.info("lesson path = " + file.getAbsoluteFile());
						if(!file.exists()){
							file.getParentFile().mkdirs();
						}else{
							FileUtils.deleteDirectory(file);
						}
						
						String lessonZip = courseFolder+File.separator + lesson.getOwnerId()+File.separator + lessonName;
						ops = new FileOutputStream(new File(lessonZip));
						IOUtils.copy(ips, ops);
						unZipFile(lessonZip);
						logger.info("lessonZip = " + lessonZip);
						String lessonFolderName = lessonName.substring(0, lessonName.lastIndexOf("."));
						String xmlFilePath = courseFolder+File.separator + lesson.getOwnerId()+File.separator +lessonFolderName + File.separator +"imsmanifest.xml";
						String lessonTitle = XMLParser
								.parseXML(xmlFilePath);
						lesson.setName(lessonTitle);
						lesson.setFolderName(lessonFolderName);
						lesson.setUpdateDate(new Date());
						lesson.setFileSize(uploadRequest.getSize("fileName"));
						LessonLocalServiceUtil.updateLesson(lesson);
					}
				
				}
		
			} catch (Exception e) {
				logger.error(e.getMessage());
				e.printStackTrace();
				SessionMessages.add(actionRequest, "error");
			}finally{
				if(ips!=null){
					try {
						ips.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
				
				if(ops!=null){
					try {
						ops.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
		}
		
		
		
		
		@ProcessAction(name = "uploadLessonPage")
		public void uploadLessonPage(ActionRequest actionRequest,
				ActionResponse actionRresponse) {
			
			try {
				logger.info(" page  =  uploadLessonPage" );
				User user = PortalUtil.getUser(actionRequest);
				if(Validator.isNotNull(user)){				
					actionRequest.setAttribute("page", "/uploadLesson.jsp");
				}

			} catch (Exception e) {
				logger.error(e.getMessage());
				e.printStackTrace();
				SessionMessages.add(actionRequest, "error");
			}  
		}
		
		
		@ProcessAction(name = "uploadLesson")
		public void uploadLesson(ActionRequest actionRequest,
				ActionResponse actionRresponse) {
			InputStream ips =null;
			OutputStream ops =null;
			logger.info("uploadLesson");
			try {
				String courseFolder = Utils.getValue("UPLOAD_PATH");
				logger.info("courseFolder=" + courseFolder);
				 
				User user = PortalUtil.getUser(actionRequest);
				UploadPortletRequest uploadRequest =
						 PortalUtil.getUploadPortletRequest(actionRequest);
				ips = uploadRequest.getFileAsStream("fileName");
				String lessonName = uploadRequest.getFileName("fileName");
			
				if(Validator.isNotNull(user)){
						String lessonFolderName = lessonName.substring(0, lessonName.lastIndexOf("."));
						File file = new File(courseFolder+File.separator + user.getUserId()+File.separator +lessonFolderName);
						logger.info("lesson path = " + file.getAbsoluteFile());
						if(!file.exists()){
							file.getParentFile().mkdirs();
						}else{
							FileUtils.deleteDirectory(file);
						}
						
						String lessonZip = courseFolder+File.separator + user.getUserId()+File.separator + lessonName;
						ops = new FileOutputStream(new File(lessonZip));
						IOUtils.copy(ips, ops);
						unZipFile(lessonZip);
						logger.info("lessonZip = " + lessonZip);
						
						String xmlFilePath = courseFolder+File.separator + user.getUserId()+File.separator +lessonFolderName + File.separator +"imsmanifest.xml";
						String lessonTitle = XMLParser
								.parseXML(xmlFilePath);
						Lesson lesson = new LessonImpl();
						
						Date date = new Date();
				      	lesson.setUuid(Utils.getUuid());
                    	lesson.setOwnerId(user.getUserId());
                    	lesson.setName(lessonTitle);
                    	lesson.setFolderName(lessonFolderName);
                    	lesson.setFileSize(uploadRequest.getSize("fileName"));
                    	lesson.setRandomString(RandomStringUtils.randomNumeric(6));
                    	lesson.setCreateDate(date);
                    	lesson.setUpdateDate(date);
                    	lesson.setShareMode(LessonShareMode.PRIVATE.ordinal());
                     	LessonLocalServiceUtil.addLesson(lesson);
					
				
				}
		
			} catch (Exception e) {
				logger.error(e.getMessage());
				e.printStackTrace();
				SessionMessages.add(actionRequest, "error");
			}finally{
				if(ips!=null){
					try {
						ips.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
				
				if(ops!=null){
					try {
						ops.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
		}
		
		
		@ProcessAction(name = "searchLesson")
		public void searchLesson(ActionRequest actionRequest,
				ActionResponse actionRresponse) {
			
			try {
				logger.info(" page  =  searchLesson" );
				String search = ParamUtil.getString(actionRequest, "search");
				if(Validator.isNotNull(search)){				
					actionRequest.setAttribute("search", search);
				}
				logger.info(" search  =" +  search);
			} catch (Exception e) {
				logger.error(e.getMessage());
				e.printStackTrace();
				SessionMessages.add(actionRequest, "error");
			}  
		}
		
		
		private void unZipFile(String strZipFile) throws ZipException, IOException {
//	        UnzipFile unzipFile = new UnzipFile();
//			String status = "";
	        long fileSize=0;
//			try {
				/*
				 * STEP 1 : Create directory with the name of the zip file
				 * 
				 * For e.g. if we are going to extract c:/demo.zip create c:/demo
				 * directory where we can extract all the zip entries
				 */
				File fSourceZip = new File(strZipFile);
				String zipPath = strZipFile.substring(0, strZipFile.length() - 4);
//				String zipPath = fSourceZip.getParentFile().getAbsolutePath();
				File temp = new File(zipPath);
				temp.mkdir();
				temp.setExecutable(true);
				temp.setReadable(true);
				temp.setWritable(true);

//				status = zipPath;
				/*
				 * STEP 2 : Extract entries while creating required sub-directories
				 */
				ZipFile zipFile = new ZipFile(fSourceZip);
				Enumeration e = zipFile.entries();

				boolean createFolder = true;

				while (e.hasMoreElements()) {
					ZipEntry entry = (ZipEntry) e.nextElement();
					File destinationFilePath = new File(zipPath, entry.getName());
					destinationFilePath.setExecutable(true);
					destinationFilePath.setReadable(true);
					destinationFilePath.setWritable(true);
					// create directories if required.
					if (createFolder) {
						destinationFilePath.getParentFile().mkdirs();
					}
					// if the entry is directory, leave it. Otherwise extract it.
					if (entry.isDirectory()) {
						continue;
					} else {
						createFolder = true;
						/*
						 * Get the InputStream for current entry of the zip file
						 * using
						 * 
						 * InputStream getInputStream(Entry entry) method.
						 */
						BufferedInputStream bis = new BufferedInputStream(
								zipFile.getInputStream(entry));

						int b;
						byte buffer[] = new byte[1024];

						/*
						 * read the current entry from the zip file, extract it and
						 * write the extracted file.
						 */
						FileOutputStream fos = new FileOutputStream(
								destinationFilePath);
						BufferedOutputStream bos = new BufferedOutputStream(fos,
								1024);

						while ((b = bis.read(buffer, 0, 1024)) != -1) {
							bos.write(buffer, 0, b);
						}

						// flush the output stream and close it.
						bos.flush();
						bos.close();

						// close the input stream.
						bis.close();
					}
	                fileSize = fileSize + destinationFilePath.length();
				}

	            zipFile.close();
	            fSourceZip.delete();

//			} catch (IOException ioe) {
//				
//				ioe.printStackTrace();
//	            //logger.error("IOError :" + ioe.getMessage());
//			}

		}
		
		
	private  void searchContainerData(RenderRequest renderRequest,RenderResponse renderResponse)
		    {
				long userId = PortalUtil.getUserId(renderRequest);
				logger.info(" userId  =" +  userId);

				String search="";
				if(renderRequest.getAttribute("search")!=null){
					search =(String) renderRequest.getAttribute("search");
				}else{
					search =ParamUtil.getString(renderRequest, "search");
				}
				String searchQuery = "%"+ search+"%";
				logger.info(" search  =" +  search);
		
		        PortletConfig portletConfig = (PortletConfig)renderRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
				ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
				  Map<String,String> paramMap= new HashMap<String,String>();
				  paramMap.put("search", search);
				  List<Lesson> lessonList =new ArrayList<Lesson>();
		 
		 	/*
			 * Creating IteratorURL and in that we will pass tab parameter
			 */
		        PortletURL iteratorURL= renderResponse.createRenderURL();
				Iterator<Map.Entry<String, String>> entries = paramMap.entrySet().iterator();
				while (entries.hasNext()) {
					Map.Entry<String, String> entry = entries.next();
					iteratorURL.setParameter(entry.getKey(), entry.getValue());
				}
		 
		 	/*
			 * Creating SearchContainer
			 */
		        SearchContainer<Lesson> searchContainer = new SearchContainer<Lesson>(renderRequest, null,
		                null, SearchContainer.DEFAULT_CUR_PARAM, ParamUtil.getInteger(renderRequest,  SearchContainer.DEFAULT_DELTA_PARAM, 10),
		                iteratorURL, null, LanguageUtil.get(portletConfig, themeDisplay.getLocale(), "No Lessons were Found"));
		        int total = 0;
		        try {
			 	/*
				 * Fetching all the User from the Current Company and added that into the userList
				 */
//		        	List<Lesson> lessons = LessonLocalServiceUtil.findByOwnerId(202);	
//		        	List<Lesson> lessons = LessonLocalServiceUtil.findByNameOrKeywordsOrDescription(search, search, search); 
		        	lessonList = LessonLocalServiceUtil.findByNameOrKeywordsOrDescriptionAndUserId(searchQuery, searchQuery, searchQuery, userId,searchContainer.getStart(), searchContainer.getEnd());
//		        	String [] strs = new String[]{search};
//		        	long [] longs = new long[]{userId};
//		        	List<Lesson> lessons = LessonLocalServiceUtil.findByNameOrKeywordsOrDescriptionAndUserId(strs, strs, strs, longs);
		        	total = LessonLocalServiceUtil.countByNameOrKeywordsOrDescriptionAndUserId(searchQuery, searchQuery, searchQuery, userId);
//	        	 lessonList = ListUtil.subList(lessons, searchContainer.getStart(), searchContainer.getEnd());
//		        	 if(lessons!=null){
//		        		 total = lessons.size(); 
//		        	 }
		        
		        } catch (SystemException e) {
		            SessionErrors.add(renderRequest, SystemException.class.getName());
		        }
		        /*
			 * Sub listing the userList depending on the delta parameter we have set in the SearchContainer.
			 */
		       
		 

		        searchContainer.setTotal(total);
		        searchContainer.setResults(lessonList);
		        renderRequest.setAttribute("searchContainer", searchContainer);
		 
		    }
	
		
}

 

 

3. 问题:

liferay service builder 问题
需要的sql 语句: select * from xxx where (a like "%123%" or b like "%123%" or c like "%123%") and  d='123'

liferay拼成的sql 语句select * from xxx where a like "%123%" and b like "%123%" and c like "%123%" and  d='123'
每次service.xml 都会改变,需要重新再加上去

 

分享到:
评论

相关推荐

    liferay标签

    通过正确配置`&lt;liferay-ui:search-container&gt;`及其子标签,如`&lt;liferay-ui:search-container-row&gt;`和`&lt;liferay-ui:search-iterator&gt;`, 开发者可以实现动态的、交互性强的搜索体验,这对于数据量大的应用程序来说尤其...

    LIferay 自带标签介绍

    `&lt;liferay-ui:search-container&gt;` 标签是Liferay中最强大的UI标签之一,它提供了一个完整的搜索界面,包括过滤器、排序、分页等功能。开发者只需要提供数据源和字段定义即可。 ### 示例和代码 在实际应用中,这些...

    liferay使用的标签

    举例来说,一个简单的使用LIFERAY-UI:SEARCHCONTAINER的场景可能是创建一个用户友好的搜索界面,用户可以输入关键词并立即看到匹配的结果。通过配置搜索容器,可以定义搜索字段、过滤器、排序方式以及结果的展示样式...

    liferay-portal-sql-6.1.1-ce-ga2-20120731132656558

    标题 "liferay-portal-sql-6.1.1-ce-ga2-20120731132656558" 暗示了这是一个关于Liferay Portal 6.1.1社区版(CE GA2)的SQL相关资源,发布日期为2012年7月31日。Liferay Portal是一个开源的企业级内容管理平台,它...

    liferay-theme-adapter:用于以编程方式实现 generator-liferay-theme 的适配器

    liferay-主题适配器 用于以编程方式实现 generator-liferay-theme 的适配器 npm install --save liferay-theme-adapter var generator = require ( 'liferay-theme-adapter' ) ; generator ( { cb : function ...

    liferay-plugins-sdk-6.1.1-20130816114619181.zip

    此外,SDK还包括了构建脚本(如`build.xml`)和配置文件(如`liferay-plugin-package.xml`),这些文件用于控制项目的构建过程和插件的元数据。`build.xml`通常使用Ant构建工具,定义了编译、测试、打包和部署的步骤...

    Liferay开发常用标签

    通过`renderResponse.createRenderURL()`创建URL,设置窗口状态和其他参数,然后在`liferay-ui:tabs`标签中使用。这种方式同样允许开发者根据用户的操作动态改变选项卡的内容。 总结起来,Liferay的标签库提供了...

    liferay-grow:期望团队成员以某种方式回馈他人

    使用以下命令克隆此仓库: https://github.com/liferay-labs-br/liferay-grow : https://github.com/liferay-labs-br/liferay-grow 使用您的首选项包管理器安装包(yarn install) 在阅读更多内容 :party_popper:...

    liferay-ide-eclipse-updatesite-1.6.2

    总结,Liferay IDE是Liferay开发者的得力助手,而“liferay-ide-eclipse-updatesite-1.6.2”则是保证开发者使用最新、最稳定版本的关键。通过定期更新,开发者可以充分利用Liferay IDE的功能,提升开发效率,打造高...

    liferay-tests:Liferay入门Pitang

    【标题】"liferay-tests:Liferay入门Pitang" 【描述】"liferay-tests:Liferay入门Pitang" 这个项目标题表明我们正在探讨一个关于Liferay的测试集,特别针对初学者的教程,名为"Pitang"。Liferay是一款开源的企业...

    liferay-tomcat:使用 Docker.io 设置 Liferay 环境

    #Liferay 在码头工人Liferay版本:liferay-portal-tomcat-6.2-ce-ga2-20140319114139101 busybox 上的基础图像以获得更小的图像(~600M) 将 tomcat 日志文件移动到 $LIFERAY_HOME/logs/tomcat 暴露端口 8080 #卷/...

    java8看不到源码-elasticsearch-docker-composer-for-liferay-7::magnifying_glass_tilted_left:Elasticsearch和K

    看不到源码elasticsearch-docker-composer-for-liferay-7 这是用于设置 docker-composer 以针对 Liferay 7.3 GA1 / DXP 7.3 SP1 (Elasticsearch 7.9.3) 测试 Elasticsearch 和 Kuromoji。 所需环境 码头工人 3.3.3 &gt;...

    liferay-ide-eclipse-updatesite-1.1.0.zip

    通过将"Liferay-ide-eclipse-updatesite-1.1.0.zip"导入Eclipse,开发者可以轻松地更新或安装Liferay IDE,确保始终使用最新版本的工具,从而获得最佳的开发体验。这不仅有利于保持代码的现代化,也有助于开发者掌握...

    Java健身管理系统源码-com-liferay-commerce:com-liferay-商务

    Java健身管理系统源码Liferay 商务 Liferay Commerce 是一个用 Java 编写的开源数字商务平台。 它从头开始构建以与 Liferay Portal 一起使用,以便 Liferay 开发人员可以在他们的商业项目中利用完全集成的 Web 内容...

    liferay-frontend-projects:包含各种前端基础架构团队项目的monorepo

    liferay-frontend-projects monorepo 欢迎来到Liferay前端基础架构团队的monorepo。 这是对 “探索项目合并以减少开销”中提出的想法的实验性探索。 指导方针 这些是曾经存在于存储库中的文档,现在位于以下位置:...

    cordova-liferay-plugin:适用于Cordova的Liferay插件

    cordova-liferay插件该插件定义了一个全局“ Liferay”对象,该对象描述了Liferay SDK的接口。 尽管对象在全局范围内,但直到'deviceready'事件之后才可用。 如果发现任何错误,请创建一个问题。 已更新为Cordova和...

    liferay-portal-src-6.0.6-20110225.part2

    liferay-portal-src-6.0.6-20110225.part2

    liferay-custom-fragments:Liferay的自定义片段的集合

    通过学习和使用“liferay-custom-fragments”项目,开发者可以深入理解如何在Liferay环境中创建和管理自定义片段,从而提升Liferay门户的用户体验和功能性。这个项目不仅适用于初学者,也对有经验的Liferay开发者有...

    docker-liferay-dxp-wildfy-postgresql:lIferay 7 ce widfly捆绑docker映像

    提供的Liferay-portal-wildfly-x捆绑包zip存档中的Liferay安装 注意:泊坞窗映像不应在生产环境中使用。 此图像基于Ikizema( )liferay docker图像: : 所需的自定义 在运行Docker构建器之前,您需要在./assets/...

    liferay-demo:Liferay示范

    这个“liferay-demo”项目是一个Liferay的示例应用,旨在帮助开发者快速理解并掌握Liferay的开发流程和关键概念。 1. **Liferay 平台概述** Liferay 提供了一个基于Java的全功能Web门户框架,支持多种服务如内容...

Global site tag (gtag.js) - Google Analytics