2013年10月2日 星期三
Liferay自訂portal的configuration畫面
有時候會要在頁面上做一些參數的控制
這時候需要利用到Portal本身的控制面板
但是原本右上角的控制面板功能可能不是你要的
(大部分都是權限控管,如果是多媒體Portal則可能是控制填入的檔案類型之類的)
這時候我們可以自訂自己的configuration
先到portlet.xml設定中
填入黃色的內容
---------------------------------------------
<portlet>
<portlet-name>NKMU-Account-Apply</portlet-name>
<display-name>NKMU Account Apply</display-name>
<portlet-class>com.liferay.util.bridges.mvc.MVCPortlet</portlet-class>
<init-param>
<name>view-template</name>
<value>/html/test.jsp</value>
</init-param>
<init-param>
<name>config-template</name>
<value>/html/configuration.jsp</value>
</init-param>
<expiration-cache>0</expiration-cache>
(以下省略)
----------------------------------------------
注意value標籤中是你要自訂的configuration,jsp頁面的位置
接下來liferay-portal.xml
填入以下黃色內容
----------------------------------------------
<portlet>
<portlet-name>TestProject</portlet-name>
<icon>/icon.png</icon>
<configuration-action-class>
com.liferay.portal.kernel.portlet.DefaultConfigurationAction
</configuration-action-class>
<header-portlet-css>/css/main.css</header-portlet-css>
------------------------------------------------
這樣在test.jsp的右上角的扳手就可以載入你自己自訂的設定頁面了
configuraion.jsp有幾個重要的設定要先寫入頁面
這樣出來的頁面才會是設定的頁面
configration.jsp基本上必須包含以下的語法
-------------------------------------------------
<%@page import="com.liferay.portal.kernel.util.Constants" %>
<portlet:defineObjects />
<liferay-portlet:actionURL portletConfiguration="true" var="configurationURL" />
<%
//這一段基本上可以放入init.jsp,這樣在jsp頁面載入時
//只要引入init.jsp即可在原本的頁面取得設定資料
PortletPreferences preferences = renderRequest.getPreferences();
String portletResource = ParamUtil.getString(request, "portletResource");
if (Validator.isNotNull(portletResource)) {
preferences = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
//這裡先設定範例變數configID
String configID= GetterUtil.getInteger(preferences.getValue("aa", null));
//這樣子打開config時就可以取得你之前設定的參數
//這裡運用顯示在自訂的輸入欄中
%>
<aui:form action="<%=configurationURL%>" method="post">
<!-- 以下是用來控制寫入的 -->
<aui:input name="<%= Constants.CMD %>" type="hidden" value="<%= Constants.UPDATE %>" />
<!-- 自訂參數輸入框
label是顯示標籤,name 是你要寫入Preferences的變數,請使用preferences--變數名稱--
這裡是用aa作為變數
-->
<aui:input label="" name="preferences--aa--" value="<%=configID %>" />
<aui:button type="submit" />
</aui:form>
--------------------------------------------------------
這樣就完成了
參考資料:
使用DefaultConfig快速開發portal Config頁面
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言