使用DefaultConfigurationAction快速开发Portlet配置页

转自 Liferay俱乐部

http://www.liferayclub.com 

 

说明:

1.com.liferay.portal.kernel.portlet.DefaultConfigurationAction这个类是Liferay自带的的配置页面保存的实现类,通过约定参数输入框的命名方式(“preferences--参数名--”)来实现默认的保存,有一定的局限性,但一般就够用了。

2.本例portlet class使用com.liferay.util.bridges.mvc.MVCPortlet

 

实现步骤:

1.在SDK想到中创建portlet时,Portlet Model把Config选上,或者在已生成的portlet.xml中,加上以下代码:

 

<init-param>
<name>config-template</name>
<value>/html/config.jsp</value>
</init-param>
 
这是指定配置页jsp位置
 
2.在liferay-portlet.xml中为需要有配置页的portlet加上configuration-action-class代码,

 

<portlet>
<portlet-name>demoportlet</portlet-name>
<icon>/img/icon.png</icon>
<instanceable>false</instanceable>
<configuration-action-class>
com.liferay.portal.kernel.portlet.DefaultConfigurationAction
</configuration-action-class>
<header-portlet-css>/css/demo/main.css</header-portlet-css>
<footer-portlet-javascript>/js/demo/main.js</footer-portlet-javascript>
<css-class-wrapper>demoportlet-portlet</css-class-wrapper>
</portlet>
 
3.config.jsp的代码,(假定我们有个参数名为objectid)
...
<portlet:defineObjects />
...省略部分代码...
 
<%
PortletPreferences preferences = renderRequest.getPreferences();
String portletResource = ParamUtil.getString(request, "portletResource");
if (Validator.isNotNull(portletResource)) {
preferences = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
}
 
int objectid = GetterUtil.getInteger(preferences.getValue("objectid", null));
%>
<liferay-portlet:actionURL portletConfiguration="true" var="configurationURL" />
<aui:form action="<%=configurationURL%>" method="post" name="fm">
<!-- 下面这个hidden也必须保留 -->
<aui:input name="<%= Constants.CMD %>" type="hidden" value="<%= Constants.UPDATE %>" />
 
<!-- 输入框名称必须格式为“preferences--参数名--” -->
<aui:input label="app-object-id" name="preferences--objectid--" value="<%= objectid %>" />
 
<aui:button type="submit" />
</aui:form>
 
效果:
portlet's config page

猜你喜欢

转载自kevinhwq.iteye.com/blog/1754219