Liferay自开发portlet的6.1到6.2升级


Liferay6.1到6.2的升级变动比它看起来要大的多。

之前在6.1下开发的portlets在升级6.2时,需要改动的地方比较多。通过这些改动可以看到liferay从6.1到6.2升级的一些变化。

1.UI问题。Liferay 6.2与6.1相比,整体风格大变,同时,开发的portlet的UI也受到了影响。

在6.1下,我们portlet使用了jquery的accordion的widget。但是,在6.2中,UI混乱了:


已然看不出来accordion的效果。

我放弃了jquery的accordion实现,采用liferay的标签类库<liferay-ui:panel-container>:

<liferay-ui:panel-container accordion="<%= true %>" extended="<%= true %>">
  <liferay-ui:panel title="ParentTable">
  </liferay-ui:panel>
  <liferay-ui:panel title="ChildTable" state='<%= "closed" %>'>
  </liferay-ui:panel>
</liferay-ui:panel-container>

效果不错:


当然了,UI的改动远不止于这一点。从这看出,liferay 6.2在UI方面巨大的改动,它采用了bootstrap的css库作为框架。对于UI的改动,只能运行portlet,来查看哪些地方需要改动。

参考:https://github.com/liferay/liferay-portal/blob/master/portal-web/docroot/html/portlet/control_panel_menu/view.jsp

2.命名空间的问题。

6.2中,Liferay默认强制规定在JSP里写的非aui元素的name属性必须加<portlet:namespace />,否则后台无法接收到元素的值。

比如,6.1中,我们前台有这样元素:

<input type="text" name="example" />

在后台直接获取就可以:

String value = request.getParameter("example");
但在6.2中,前台元素必须写成:
<input type="text" name="<portlet:namespace />example" />
后台才能获取到。值得注意的是,后台代码不必加namespace。

ajax中的data也是要加namespace的:

<span style="white-space:pre">	</span>jQuery.ajax({
		url: "<portlet:resourceURL id='${namespace}getColumns' />",
		type:"POST",
		data:{<portlet:namespace />selectedTable:selectedTable, <portlet:namespace />tabName:tabName},
		dataType:"json",
		async: false,
		success: function (data, status){
		}
	});

当然,如果懒得为我们portlet中繁多的元素加namespace,可以在liferay-portlet.xml中设置属性:

	<portlet>
		<portlet-name>example</portlet-name>
		<icon>/images/icon.png</icon>
		<maximize-edit>true</maximize-edit>
		<instanceable>true</instanceable>
		<private-session-attributes>false</private-session-attributes>
		<requires-namespaced-parameters>false</requires-namespaced-parameters> 
		<header-portlet-css>/css/tripleTableDatagrid.css</header-portlet-css>
		<footer-portlet-javascript>
			/js/main.js
		</footer-portlet-javascript>
		<css-class-wrapper>tripletabledatagrid-portlet</css-class-wrapper>
	</portlet>
参考:http://blog.csdn.net/paranoid_android/article/details/11655813

3.改dependency。portlet所依赖的liferay的jar包,必须重新引6.2版本的。因为这涉及到一些api的改动。我在改动的时候就遇到了

ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
themeDisplay获取不到的问题。据介绍,这是因为WebKeys.THEME_DISPLAY在6.1与6.2中的定义不同了导致的。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值