會這樣寫的用意是可以自由讓 header 放在想要的地方,只要在config裡面做設定就好了。
config.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@include file="/html/init.jsp"%>
<%
String tabs2 = ParamUtil.getString(request, "tabs2", "display-settings");
String redirect = ParamUtil.getString(request, "redirect");
%>
<liferay-portlet:renderURL portletConfiguration="true" var="portletURL">
<portlet:param name="tabs2" value="<%= tabs2 %>" />
<portlet:param name="redirect" value="<%= redirect %>" />
</liferay-portlet:renderURL>
<liferay-portlet:actionURL portletConfiguration="true"
var="configurationURL" />
<aui:form action="<%=configurationURL%>" method="post" name="fm" onSubmit='<%= "event.preventDefault(); " + renderResponse.getNamespace() + "saveConfiguration();" %>'>
<aui:input name="<%=Constants.CMD%>" type="hidden" value="<%=Constants.UPDATE%>" />
<aui:input name="tabs2" type="hidden" value="<%= tabs2 %>" />
<aui:input name="redirect" type="hidden" value="<%= redirect %>" />
<%
String tabs2Names = "display-settings,rss";
%>
<liferay-ui:tabs
names="<%= tabs2Names %>"
param="tabs2"
url="<%= portletURL %>"
/>
<c:choose>
<c:when test='<%= tabs2.equals("display-settings") %>'>
<aui:input name="preferences--newsColumns--" type="hidden"/>
<liferay-ui:panel-container extended="<%= true %>" id="newsSettingsPanelContainer" persistState="<%= true %>">
<liferay-ui:panel collapsible="<%= true %>" extended="<%= true %>" id="newsEntriesListingPanel" persistState="<%= true %>" title="新聞列表欄位顯示">
<aui:fieldset>
<aui:field-wrapper label="顯示的欄位">
<%
Set<String> availableNewsColumns = SetUtil.fromArray(StringUtil.split(allNewsColumns));
// Left list
List leftList = new ArrayList();
for (String newsColumn : newsColumns) {
leftList.add(new KeyValuePair(newsColumn, LanguageUtil.get(pageContext, newsColumn)));
}
// Right list
List rightList = new ArrayList();
Arrays.sort(newsColumns);
for (String entryColumn : availableNewsColumns) {
if (Arrays.binarySearch(newsColumns, entryColumn) < 0) {
rightList.add(new KeyValuePair(entryColumn, LanguageUtil.get(pageContext, entryColumn)));
}
}
rightList = ListUtil.sort(rightList, new KeyValuePairComparator(false, true));
%>
<liferay-ui:input-move-boxes
leftBoxName="currentEntryColumns"
leftList="<%= leftList %>"
leftReorder="true"
leftTitle="目前的"
rightBoxName="availableEntryColumns"
rightList="<%= rightList %>"
rightTitle="可用的"
/>
</aui:field-wrapper>
</aui:fieldset>
</liferay-ui:panel>
</liferay-ui:panel-container>
</c:when>
<c:when test='<%= tabs2.equals("rss") %>'>
<liferay-ui:rss-settings
delta="<%= rssDelta %>"
displayStyle="<%= rssDisplayStyle %>"
enabled="<%= enableRSS %>"
feedType="<%= rssFeedType %>"/>
</c:when>
</c:choose>
<aui:button type="submit" />
</aui:form>
<aui:script>
Liferay.provide(
window,
'<portlet:namespace />saveConfiguration',
function() {
<c:choose>
<c:when test='<%= tabs2.equals("display-settings") %>'>
document.<portlet:namespace />fm.<portlet:namespace />newsColumns.value = Liferay.Util.listSelect(document.<portlet:namespace />fm.<portlet:namespace />currentEntryColumns);
</c:when>
</c:choose>
submitForm(document.<portlet:namespace />fm);
},
['liferay-util-list-fields']
);
</aui:script>
然後在init.jsp裡面加入config需要的表頭設定
//searchContainer;
String defaultNewsColumns = "title,category,status,priority,action";
String allNewsColumns = defaultNewsColumns + ",createDate,userName,viewCount";
String[] newsColumns = StringUtil.split(PrefsParamUtil.getString(portletPreferences, request, "newsColumns", defaultNewsColumns));
再來這是list.jsp , SearchContainer不用tag的方式 , 改用JAVA的寫法。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="/html/init.jsp"%>
<%
PortletURL listURL = renderResponse.createRenderURL();
listURL.setParameter("jspPage", "/html/news/latestnews_list.jsp");
listURL.setWindowState(WindowState.NORMAL);
String searchDateId = "searchDateId";
int listCount = 0 ;
ThemeDisplay display = (ThemeDisplay) request
.getAttribute(WebKeys.THEME_DISPLAY);
RowChecker rowChecker = null;
if (permissionChecker.isGroupAdmin(display.getScopeGroupId())
|| permissionChecker.isOmniadmin()) {
rowChecker = new RowChecker(renderResponse);
}
ResourceURL rssURL = liferayPortletResponse.createResourceURL();
//rssURL.setParameter("p_l_id", String.valueOf(plid));
SearchContainer searchContainer = new SearchContainer(liferayPortletRequest,
null, null, "news",
SearchContainer.DEFAULT_DELTA,
SearchContainer.DEFAULT_DELTA,
listURL,
null, null);
List<String> headerNames = new ArrayList<String>();
for (String headerName : newsColumns) {
headerNames.add(headerName);
}
searchContainer.setRowChecker(rowChecker);
searchContainer.setHeaderNames(headerNames);
List results = null;
int total = 0;
results = NewsLocalServiceUtil.findByTop();
total = results.size();
searchContainer.setResults(results);
searchContainer.setTotal(total);
List resultRows = searchContainer.getResultRows();
for(int i = 0 ; i < results.size(); i++){
News news = (News)results.get(i);
ResultRow row = new ResultRow(news, news.getPrimaryKey(), i);
PortletURL rowURL = liferayPortletResponse.createRenderURL();
rowURL.setParameter("jspPage", "/html/news/latestnews_view.jsp");
rowURL.setParameter("redirect", currentURL);
rowURL.setParameter("newsId", String.valueOf(news.getNewsId()));
for (Object column : searchContainer.getHeaderNames()) {
String columnName = (String)column;
if (columnName.equals("action")) {
row.addJSP("/html/news/latestnews_action.jsp");
}
if (columnName.equals("createDate")) {
row.addDate(news.getCreateDate());
}
if (columnName.equals("title")) {
//TextSearchEntry fileEntryTitleSearchEntry = new TextSearchEntry();
//fileEntryTitleSearchEntry.setName(news.getTitle());
//row.addSearchEntry(fileEntryTitleSearchEntry);
row.addText(StringUtil.shorten(news.getTitle(), 100), rowURL);
}
if (columnName.equals("category")) {
row.addText(news.getCategory());
}
if (columnName.equals("viewCount")) {
row.addText(String.valueOf(news.getViewCount()));
}
if (columnName.equals("status")) {
row.addStatus(news.getStatus(),news.getStatusByUserId(),news.getStatusDate());
}
if (columnName.equals("userName")) {
row.addText(news.getUserName());
}
if (columnName.equals("priority")) {
row.addText(String.valueOf(news.getPriority()));
}
}
resultRows.add(row);
}
%>
<portlet:renderURL var="createNewURL">
<portlet:param name="backURL" value="<%=currentURL%>" />
<portlet:param name="<%=NewsConstants.CMD%>" value="<%=NewsConstants.ADD%>" />
<portlet:param name="jspPage" value="/html/news/latestnews_edit.jsp" />
</portlet:renderURL>
<portlet:renderURL var="categoryMgtURL" windowState="<%=LiferayWindowState.MAXIMIZED.toString() %>">
<portlet:param name="backURL" value="<%=currentURL %>" />
<portlet:param name="jspPage" value="/html/news/category/category_mgt.jsp" />
</portlet:renderURL>
<portlet:renderURL var="viewPermissionMgtURL" windowState="<%=LiferayWindowState.MAXIMIZED.toString() %>">
<portlet:param name="backURL" value="<%=currentURL %>" />
<portlet:param name="jspPage" value="/html/news/viewpermission/vp_list.jsp" />
</portlet:renderURL>
<portlet:actionURL name="deleteList" var="dellistURL"/>
<portlet:actionURL name="searchNews" var="searchURL"/>
<aui:form action="<%=searchURL%>" method="post">
<%--
<aui:input type="hidden" name="redirect" value="<%=currentURL %>"/>
--%>
<aui:nav-bar>
<aui:nav>
<aui:nav-item href="${categoryMgtURL}" label="新聞類別管理" title="新聞類別管理"/>
<aui:nav-item href="${viewPermissionMgtURL}" label="檢視權限管理" title="檢視權限管理" name="addAnnouncementButton" />
</aui:nav>
<aui:nav-bar-search cssClass="pull-right">
<div class="form-search">
類別
<aui:select name="" label="" inlineField="true" inlineLabel="left" style="width:100px;">
</aui:select>
時間區間
<aui:input id="<%=searchDateId %>" name="startDate" value="" label="" inlineField="true" style="width:70px;"/>
~
<aui:input id="<%=searchDateId %>" name="endDate" value="" label="" inlineField="true" style="width:70px;"/>
<liferay-ui:input-search autoFocus="<%= windowState.equals(WindowState.MAXIMIZED) %>" id="keywords1" name="keywords" placeholder='<%=LanguageUtil.get(locale, "keywords")%>' title="關鍵字"/>
</div>
</aui:nav-bar-search>
</aui:nav-bar>
</aui:form>
<a class="btn btn-info btn-large" href="<%=createNewURL %>">
<i class="icon-plus-sign icon-large"></i>新增新聞
</a>
<br>
<div style="float: right;" >
<liferay-ui:rss
delta="<%= rssDelta %>"
displayStyle="<%= rssDisplayStyle %>"
feedType="<%= rssFeedType %>"
resourceURL="<%= rssURL %>" />
</div>
<liferay-ui:search-iterator paginate="<%= false %>" searchContainer="<%= searchContainer %>" />
<aui:script>
AUI().use('aui-datepicker', function(A) {
new A.DatePicker({
trigger: '#<portlet:namespace />searchDateId',
popover: {zIndex: 1 },
calendar: {
dates: ['10/01/2014'],
dateFormat: '%Y/%m/%d'
},
on: {
selectionChange: function(event) {
console.log(event.newSelection)
}
}
});
});
</aui:script>
沒有留言:
張貼留言