SearchContainer的用法说明

本文详细介绍了Liferay平台中SearchContainer组件的使用方法,包括Table标题行配置、SearchContainer创建、Table内容填充及分页显示等关键步骤。
SearchContainer的用法说明
在Liferay中,列表通常是使用SearchContainer来实现的,如BBS的栏目列表等。在Liferay的源代码中,JSP夹杂了大量的本应在Action中实现的代码,因此导致很难看懂。我尝试写一个Portlet,结果就在JSP处耗费了很长时间。

在此简单总结一下SearchContainer的用法,内容有些不恰当。具体可参考message_boards/view.jsp中的代码。

1.1 概述
作为一个条目的列表,应该包括几个方面的内容:

l Table的标题行

l Table的内容

l 每一个条目允许的操作

l 分页

1.2 Table的标题行(不同的liferay版本可能有所不同,但实质是一样的)
标题行相对比较简单,核心代码如下:

List headerNames = new ArrayList();

headerNames.add("news.column");

headerNames.add("news.columndescript");

headerNames.add("news.childcolumns");

headerNames.add(StringPool.BLANK);

其中注意两点:

1、 每个标题,应该是i18n的资源,需要在资源文件language.properties中添加内容。

2、 最后一行,是用来显示可能的操作按钮的,不需要标题行。

1.3 创建SearchContainer
根据这个headerNames来创建SearchContainer。

首先需要生成一个PortletURL对象,并包括必要的参数

PortletURL portletURL = res.createRenderURL();

portletURL.setParameter("struts_action", "/ext/news/columnadmin/view");

portletURL.setParameter("columnId", columnId);

如果页面是分为多个Tab的,还需要将Tab也添加进去。

然后就可以创建SearchContainer

SearchContainer searchContainer = new SearchContainer(req, null, null,"column",

SearchContainer.DEFAULT_DELTA, portletURL,headerNames, null);

检查源代码,SearchContainer函数的定义为

SearchContainer(
RenderRequest req, //javax.portlet.RenderRequest
DisplayTerms displayTerms, //具体意义还不是很清楚,一般设置为null
DisplayTerms searchTerms, //具体意义还不是很清楚,一般设置为null
String curParam, //当前操作的列表,如果某个JSP页面中有两个列表需要分页,则此参数可以分别设置为“cur1”和“cur2”,暂时没发现有什么影响
int delta, //设置每页显示的记录数,默认的是20,可以修改此设置
PortletURL iteratorURL, //设置被循环的每条记录的操作URL
List headerNames, //设置表头信息
String emptyResultsMessage //当查询结果为空时,即数据库中无数据供列表显示时所显示的内容,如果设置为null,则列表表头也不显示出来,也可以设置为“暂无数据”等
)

这一步同创建headerNames应该是可以互换的,用searchContainer.setHeaderNames()即可。

1.4 Table的内容
主要由几个小步骤完成

1.4.1 设置总条数
searchContainer.setTotal(total);
1.4.2 直接设置查询结果
searchContainer.setResults(results)
变量是一个List,其中的每一个对象将会被用到下一个设置可执行操作的JSP中。
1.4.3 设置Table的显示条目
List resultRows = searchContainer.getResultRows();

for (int i = 0; i < results.size(); i++) {

NewsColumn cutColumn = (NewsColumn) results.get(i);

// 生成新的一个显示行

ResultRow row = new ResultRow(cutColumn, cutColumn.getPrimaryKey() .toString(), i);

// 设置URL

PortletURL rowURL = res.createRenderURL();

rowURL.setWindowState(WindowState.MAXIMIZED);

rowURL.setParameter("struts_action", "/ext/news/columnadmin/view");

rowURL.setParameter("columnId", cutColumn.getColumnId());

// 设置每一列的显示内容

row.addText(cutColumn.getName(), rowURL);

row.addText(cutColumn.getDescription(), rowURL);

row.addText(childCount), rowURL);

// 设置每一个条目的可用操作

row.addJSP("right", SearchEntry.DEFAULT_VALIGN, "*.jsp");

resultRows.add(row);

}

1.5 每一个条目允许的操作
通过row.addJSP("right", SearchEntry.DEFAULT_VALIGN, "column_action.jsp")来调用JSP显示相应的操作。

在JSP中,通过下面的语句能够获取当前条目的 model 对象

ResultRow row = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);

MBCategory category = (MBCategory)row.getObject();

拿到model之后,通过<c:if test="<%= MBCategoryPermission.contains 方式判断权限,如果允许操作,则首先生成相应的portletURL,然后显示icon图标。

<c:if test="<%= MBCategoryPermission.contains(permissionChecker, category, ActionKeys.UPDATE) %>">

<portlet:renderURL windowState="<%= WindowState.MAXIMIZED.toString() %>" var="portletURL">

<portlet:param name="struts_action" value="/message_boards/edit_category" />

<portlet:param name="redirect" value="<%= currentURL %>" />

<portlet:param name="categoryId" value="<%= category.getCategoryId() %>" />

</portlet:renderURL>

<liferay-ui:icon image="edit" url="<%= portletURL %>" />

</c:if>

这部分代码涉及到Liferay的权限机制。

1.6 显示table和分页
显示table很简单,在JSP中

<liferay-ui:search-iterator searchContainer="<%= searchContainer %>" />

SearchContainer自身支持分页。以下几步

l 创建SearchContainer时设置每页显示的条数

构造函数SearchContainer的第四个参数int delta就是每页显示的条数,缺省使用SearchContainer.DEFAULT_DELTA,表示每页显示20条。我们可以用其他任何我们喜欢的数值。

l 从逻辑层取数据时提供begin和end参数

searchContainer.getStart() 和searchContainer.getEnd()

l 显示分页信息

<liferay-ui:search-paginator searchContainer="<%= searchContainer %>" />

注意:如果因为URL缺其他参数设置而导致分页后的页面不能正常显示,则可以在
<liferay-ui:search-iterator searchContainer="<%= searchContainer %>" />
<liferay-ui:search-paginator searchContainer="<%= searchContainer %>" />标签之间定义URL,并将需要的参数设置进去;
例如:
<liferay-ui:search-iterator searchContainer="<%= searchContainer %>" />
<%
//解决分页时点击下一页或是最后一页时显示的问题
PortletURL pUrl=renderResponse.createRenderURL();
pUrl=searchContainer.getIteratorURL();
pUrl.setParameter("curAction","viewMagazineEntry");
pUrl.setParameter("magazineTitleId",String.valueOf(magazineTitle.getMagazineTitleId()));
searchContainer.setIteratorURL(pUrl);
%>
<liferay-ui:search-paginator searchContainer="<%= searchContainer %>" />
有网页的源码,怎么在idea里用vue复现,运用element-UI组件,view-source:https://rloopbase.nju.edu.cn/ ,源码如下: <html xmlns="http://www.w3.org/1999/xhtml " xml:lang="en" lang="en"> <link rel="stylesheet" type="text/css" href="/css/myIndex.css"> <head> <title>R-loopBase</title> <link rel="icon" href="/images/icon-rloop-purple-circle-2.png" type="image/x-icon"> </head> <body> <div class="container"> <div class="indexBar"></div> <div class="card"> <!-- Introduction --> <div class="cardTitle"> Introduction </div> <div class="cardContext"> <p id="introductionText" class="cardP">The R-loop, a three-stranded nucleic acid structure composed of an RNA:DNA hybrid and a displaced single-stranded DNA, plays versatile roles in many physiological and pathological processes. However, its controversial genomic localization and incomplete understanding of its regulatory network raise great challenges for R-loop research. Here, we present R-loopBase to tackle these pressing issues by systematic integration of a huge amount of genomics and literature data. A reference set of human R-loop zones is computed with confidence scores and detailed annotations (<span style="font-weight: bold"><a href="/index.jsp">Search</a></span>, <span style="font-weight: bold"><a href="/help.jsp">Help</a></span> and <span style="font-weight: bold"><a href="/download.jsp">Download</a></span>), all of which can be visualized in well-annotated genomic context in a local genome browser (<span style="font-weight: bold"><a href="https://rloopbase.nju.edu.cn/browser/cgi-bin/hgTracks ">Browser</a></span>). A list of 1,185 R-loop regulators is manually curated from PubMed literatures and annotated with most up-to-date multi-omics data (<span style="font-weight: bold"><a href="/rloopRegulator.jsp">Regulator</a></span></span>). We have also manually curated 24 R-loop regulators in mouse, 63 in yeast (<i>saccharomyces cerevisiae</i>) and 21 in <i>Escherichia coli</i> to facilicate R-loop research in these model organisms (<span style="font-weight: bold"><a href="/rloopRegulator.jsp">Regulator</a></span>). We further deduce the functional relationship between individual R-loops and their putative regulators (<span style="font-weight: bold"><a href="/rloopRegulator.jsp">Regulator</a></span> and <span style="font-weight: bold"><a href="/download.jsp">Download</a></span>). In total, we have generated billions of entries of functional annotations, which can be easily accessed in our user-friendly interfaces (<span style="font-weight: bold"><a href="/help.jsp">Help</a></span>). The regulator summary and genomic annotation of R-loop regions will be constantly updated along the research progress of field. You are welcome to contribute to updating R-loop regulators and related literatures (Regulator Updating System on <span style="font-weight: bold"><a href="/rloopRegulator.jsp">Regulator</a></span> page). Any suggestions and feedbacks from you are also welcome (<span style="font-weight: bold"><a href="/contact.jsp">Contact</a></span>). </p> </div> <a href="##"><div id="showIntroduction" onclick="showMoreOrLess()" style="text-decoration: underline; text-align: right; padding-right: 20px; margin-top: -15px;">Show more</div></a> <hr class="cardHr"> </div> <!-- Introduction --> <div class="searchContainer"> <div class="searchLogo"> <ul> <li class="searchLogoText">R-loopBase</li> <li class="searchLogoImg"><img src="/images/icon-rloop-purple-circle-2.png" style="height: 60px;"></li> </ul> </div> <div class="searchForm"> <input id="searchText" type="text" name="" placeholder="e.g. BRCA2 or chr1:154572702-154628593" onkeypress="handle(event)"> <a href="#"><div class="searchItem" href="#" onclick="toGeneList()"> <i>search</i> </div></a> </div> </div> <div class="horizontalMenu"> <!-- horizontal menu --> <ul id="indexNavigator"> <li> <a href="/browser/cgi-bin/hgTracks"> <img src="/images/browser.png"> <div>Browser</div> </a> </li> <li> <a href="/rloopRegulator.jsp"> <img src="/images/regulator.png"> <div>Regulator</div> </a> </li> <li> <a href="https://rloopbase.nju.edu.cn/deepr/tool/model "> <img src="/images/tool.png"> <div>Tool</div> </a> </li> <li> <a href="/download.jsp"> <img src="/images/download.png"> <div>Download</div> </a> </li> <li> <a href="/help.jsp"> <img src="/images/help.png"> <div>Help</div> </a> </li> <li> <a href="/contact.jsp"> <img src="/images/contact.png"> <div>Contact</div> </a> </li> </ul> </div> <!-- horizontal menu --> <div class="twoCardContainer"> <div class="card cardLeft"><!-- News --> <div class="cardTitle"> News </div> <div class="cardContext" id="newsDiv" style="overflow:hidden;clear:both;height:220px"> <ul> <li>2023.10.01 Online of <a href='https://rloopbase.nju.edu.cn/deepr/tool/model '>DeepER</a>, an R-loop prediction tool.</li> <li>2022.02.19 A new <a href="https://doi.org/10.1101/2022.02.18.480986 ">preprint</a> by R-loopBase team.</li> <li>2021.11.18 Published on <a href="https://doi.org/10.1093/nar/gkab1103 ">Nucleic Acids Res</a>.</li> <li>2021.06.20 Official release of R-loopBase v1.0.</li> <li>2021.06.15 Internal evaluation before public release.</li> <li>2021.05.10 Build-up of R-loopBase genome browser.</li> <li>2021.03.31 Data freeze for R-loopBase v1.0.</li> <li>2021.01.18 Launching R-loopBase project.</li> <li>2020.10.10 Systematic evalation of all R-loop mapping technologies.</li> </ul> </div> <a href="##"><div id="showNews" onclick="showMoreOrLess2()" style="text-decoration: underline; text-align: right; padding-right: 20px; margin-top: 4px;">Show more</div></a> <hr class="cardHr"> </div><!-- News --> <div class="card cardRight"> <!-- Publication --> <div class="cardTitle"> Latest Publications </div> <div class="cardContext" id="publicationDiv"> <ul> <li><a style="color: black" href="https://pubmed.ncbi.nlm.nih.gov/38590928/ ">LUC7L3 is a downstream factor of SRSF1 and prevents genomic instability.</a> Cell Insight. 2024.</li> <li><a style="color: black" href="https://pubmed.ncbi.nlm.nih.gov/38677845/ ">Smartphone-based device for rapid and single-step detection of piRNA-651 using anti-DNA:RNA hybrid antibody and enzymatic signal amplification.</a> Anal Chim Acta. 2024.</li> <li><a style="color: black" href="https://pubmed.ncbi.nlm.nih.gov/38609257/ ">Split activator of CRISPR/Cas12a for direct and sensitive detection of microRNA.</a> Anal Chim Acta. 2024.</li> </ul> <div style="width: 100%; text-align: right; margin-top: -4px;"><a href="https://pubmed.ncbi.nlm.nih.gov/?term=%28R-loop%29+OR+%28R-loops%29+OR+%28%22RNA+DNA+hybrid%22%29+OR+%28%22RNA+DNA+hybrids%22%29+OR+%28%22DNA+RNA+hybrid%22%29+OR+%28%22DNA+RNA+hybrids%22%29&sort=pubdate ">More publications in PubMed</a></div> </div> <hr class="cardHr"> </div> <!-- Publication --> </div> <div class="footer"> <div style="background-color: rgb(90,19,92); height: 60px; line-height: 60px; text-align: center; color: white; "> <div style="display: inline-block; height: 20px; line-height: 20px; margin-top: 15px; margin-bottom: 4px;">© 2020-2025 NANJING UNIVERSITY. ALL RIGHTS RESERVED. </div> <div style="height: 20px; line-height: 20px; margin-top: 0px;">CONDITIONS OF USE</div> </div> </div> </div> <!-- container --> </body> </html> <script type="text/javascript" language="JavaScript"> function handle(e){ if(e.keyCode === 13){ e.preventDefault(); // Ensure it is only this code that runs toGeneList(); } } function toGeneList(){ //var type = document.getElementById('searchSelect').value; var type; var value = document.getElementById('searchText').value; if(value==''){ alert("Please input keyword!"); }else if(value.match(/[^a-zA-Z0-9:-]/)){ alert("Only numbers, letters, \":\" and \"-\" are allowed!"); }else{ //top.location = '/geneList.jsp?searchFor=' + type + '&keyword=' + value; if(value.match(/^chr.+:\d+-\d+$/)){ type="location"; }else{ type="symbols"; } top.location = '/rloopList.jsp?searchFor=' + type + '&keyword=' + value; } } function changeLiSize(){ var selectId = document.getElementById("myNavigator"); } function showMoreOrLess(){ var selectId = document.getElementById("showIntroduction"); var selectText = document.getElementById("introductionText"); if(selectId.innerText == "Show more"){ selectText.style.height="auto"; selectId.innerText="Show less"; }else{ selectText.style.height="120px"; selectId.innerText="Show more"; } } function showMoreOrLess2(){ var selectId2 = document.getElementById("showNews"); var selectText2 = document.getElementById("newsDiv"); if(selectId2.innerText == "Show more"){ selectText2.style.height="auto"; selectId2.innerText="Show less"; }else{ selectText2.style.height="220px"; selectId2.innerText="Show more"; } } var publicationDivHeight = document.getElementById('publicationDiv').clientHeight; </script>
07-29
<!doctype html> <html class="no-js" lang=""> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title></title> <link rel="stylesheet" href="css/style.css"> <link rel="stylesheet" href="css/kuding.css"> <link rel="stylesheet" href="css/product-styles.css"> <meta name="description" content=""> <meta property="og:title" content=""> <meta property="og:type" content=""> <meta property="og:url" content=""> <meta property="og:image" content=""> <meta property="og:image:alt" content=""> <link rel="icon" href="/favicon.ico" sizes="any"> <link rel="icon" href="/icon.svg" type="image/svg+xml"> <link rel="apple-touch-icon" href="icon.png"> <link rel="manifest" href="site.webmanifest"> <meta name="theme-color" content="#fafafa"> </head> <body> <script > // 搜索框点击显示下拉面板 const searchInput = document.getElementById('search-input'); const searchDropdown = document.getElementById('search-dropdown'); const searchContainer = document.querySelector('.search-container'); const resultPage = document.getElementById('result-page'); searchInput.addEventListener('focus', () => { searchDropdown.style.display = 'block'; }); // 点击页面其他区域隐藏下拉面板 document.addEventListener('click', (e) => { if (!searchContainer.contains(e.target)) { searchDropdown.style.display = 'none'; } }); // 跳转到搜索结果页面 function goToResult(keyword) { const resultTitle = document.getElementById('result-title'); resultTitle.textContent = `搜索结果:${keyword}`; searchContainer.style.display = 'none'; resultPage.style.display = 'block'; } // 返回搜索页面 function goBack() { resultPage.style.display = 'none'; searchContainer.style.display = 'block'; } // 搜索按钮逻辑 const searchBtn = document.getElementById('search-btn'); searchBtn.addEventListener('click', () => { const keyword = searchInput.value.trim(); if (keyword) { goToResult(keyword); // 实际项目中可在此处添加“添加到历史搜索”逻辑 } }); </script> <div class="AllDiv"> <!---顶部菜单栏(固定位置和高度:100px)---> <div class="TopNavigation"> <div id="toplogo">XianCai</div> <div class="search-container"> <!-- 搜索框区域 --> <div class="search-box"> <input type="text" id="search-input" placeholder="搜索你想要的宝贝..."> <button id="search-btn">搜索</button> </div> <!-- 搜索下拉面板(默认隐藏,点击搜索框显示) --> <div class="search-dropdown" id="search-dropdown"> <!-- 历史搜索 --> <div class="dropdown-section"> <h3 class="section-title">历史搜索</h3> <ul class="history-list" id="history-list"> <li class="history-item" onclick="goToResult('二手笔记本电脑')">二手笔记本电脑</li> <li class="history-item" onclick="goToResult('闲置连衣裙')">闲置连衣裙</li> <li class="history-item" onclick="goToResult('家用咖啡机')">家用咖啡机</li> <li class="history-item" onclick="goToResult('考研真题')">考研真题</li> </ul> </div> <!-- 推荐搜索 --> <div class="dropdown-section"> <h3 class="section-title">大家都在搜</h3> <ul class="recommend-list" id="recommend-list"> <li class="recommend-item" onclick="goToResult('二手手机')">二手手机</li> <li class="recommend-item" onclick="goToResult('露营装备')">露营装备</li> <li class="recommend-item" onclick="goToResult('儿童绘本')">儿童绘本</li> <li class="recommend-item" onclick="goToResult('厨房小家电')">厨房小家电</li> </ul> </div> </div> </div> <!-- 搜索结果页面(默认隐藏) --> <div class="result-page" id="result-page" style="display: none;"> <div class="back-btn" onclick="goBack()">← 返回搜索</div> <h2 class="result-title" id="result-title">搜索结果:</h2> <p class="result-tip">点击历史/推荐项后,此处会显示对应关键词的搜索结果(实际项目中需对接后端接口)</p > </div> </body> </html>
最新发布
09-20
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值