Portlet配置(Configuration)开发
应用场景:比如左侧菜单树,每个一级会有一个节点图标,我们通过配置,可以随时更新图标。所以图票取自文档库。
Portlet.xml配置
<portlet>
<portlet-name>leftmenuv2</portlet-name>
<display-name>leftmenuv2</display-name>
<portlet-class>com.yixin.LeftMenuv2.LeftMenuV2</portlet-class>
<init-param>
<name>view-template</name>
<value>/html/leftmenuv2/view.jsp</value>
</init-param>
<init-param>
<name>config-template</name>
<value>/html/leftmenuv2/configuration.jsp</value>
</init-param>
…
Liferay-portlet.xml配置文件
<portlet>
<portlet-name>leftmenuv2</portlet-name>
<icon>/icon.png</icon>
<struts-path>leftmenuv2</struts-path>
<configuration-action-class>com.liferay.portal.kernel.portlet.DefaultConfigurationAction</configuration-action-class>
…
Configuration.jsp
注: lable是中文名字,配置一下国际化。
Input name要以preferences--开头
<%@include file="/html/init.jsp" %>
<%
StringimageURLFromDocumentlibrary =portletPreferences.getValue("imageURLFromDocumentlibrary",String.valueOf("imageURLFromDocumentlibrary"));
%>
<liferay-portlet:actionURLportletConfiguration="true" var="configurationActionURL"/>
<liferay-portlet:renderURLportletConfiguration="true" var="configurationRenderURL"/>
<aui:formaction="<%= configurationActionURL %>" method="post"name="fm">
<aui:inputname="<%= Constants.CMD %>" type="hidden"value="<%= Constants.UPDATE %>" />
<aui:inputname="redirect" type="hidden" value="<%=configurationRenderURL %>" />
<aui:fieldset>
<aui:inputname="preferences--imageURLFromDocumentlibrary--"label="imageURLFromDocumentlibrary"type="text" value="<%= imageURLFromDocumentlibrary%>" />
</aui:fieldset>
<aui:button-row>
<aui:buttontype="submit" />
</aui:button-row>
</aui:form>
View.jsp中读取
<%
StringimageURLFromDocumentlibrary =portletPreferences.getValue("imageURLFromDocumentlibrary",String.valueOf("imageURLFromDocumentlibrary"));
%>