使用DefaultConfigurationAction快速开发Portlet配置页

说明:

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


最后,欢迎大家加入Liferay俱乐部:http://www.liferayclub.com 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值