? Liferay
在用戶第一次登陸后,都會為其產生一個默認的私有首頁
Layout。?在
Liferay早期版本,可以在系統管理員管理界面中,配置默認的group layout。但是在4.1版本中已經沒有這個功能,所以默認情況下,新注冊的用戶,在登陸后,首先看到的其私有place都是一樣的內容,而這些內容都是liferay提供的。
?
public
?
class
?LayoutCopy?
{
????
????
private
?
static
?Log?_log?
=
?LogFactory.getLog(LayoutCopy.
class
);
????
????
private
?User?user;
????
private
?String?ownerId;
???
private
?Group?userGroup;
???
public
?LayoutCopy(User?user)?
{
???????
super
();
???????
this
.user?
=
?user;
????????
this
.ownerId?
=
?getOwnerId(user.getGroup().getGroupId(),?
false
);
???????
this
.userGroup?
=
?user.getGroup();
???}
???
public
?
void
?copyDefaultUserLayout(HttpServletRequest?httpReq)
???????????
throws
?SystemException,?PortalException?
{
??????
//
?set?in?the?portal-ext.properties:
???????
//
?default.user.layout.group=Default?User
???????
//
?and?create?then?group/community?"Default?User"?
???????
//
?CWPPropsUtil.DEFUALT_USER_LAYOUT_GROUP?=?"default.user.layout.group"
???????Group?group?
=
?GroupLocalServiceUtil.getGroup(user.getCompanyId(),
???????????????PropsUtil.get(
"
default.user.layout.group
"
));
???????
try
?
{
???????????String?groupOwnerId?
=
?getOwnerId(group.getGroupId(),?
true
);
???????????List?privateLayouts?
=
?LayoutLocalServiceUtil
???????????????????.getLayouts(groupOwnerId);
???????????
for
?(Iterator?itr?
=
?privateLayouts.iterator();?itr.hasNext();)?
{
???????????????Layout?layout?
=
?(Layout)?itr.next();
???????????????Layout?newLayout?
=
?copyLayout(layout);
???????????????copyPreferences(httpReq,?newLayout,?layout);
???????????}
???????}
?
catch
?(PortalException?e)?
{
???????????_log.error(
"
Cannot?copy?private?layouts
"
,?e);
???????}
?
catch
?(Exception?e)?
{
???????????_log.error(
"
Cannot?copy?public?layouts
"
,?e);
???????}
???????
try
?
{
???????????String?groupOwnerId?
=
?getOwnerId(group.getGroupId(),?
false
);
???????????List?publicLayouts?
=
?LayoutLocalServiceUtil
???????????????????.getLayouts(groupOwnerId);
???????????
for
?(Iterator?itr?
=
?publicLayouts.iterator();?itr.hasNext();)?
{
???????????????Layout?layout?
=
?(Layout)?itr.next();
???????????????Layout?newLayout?
=
?copyLayout(layout);
???????????????copyPreferences(httpReq,?newLayout,?layout);
???????????}
???????}
?
catch
?(PortalException?e)?
{
???????????_log.error(
"
Cannot?copy?public?layouts
"
,?e);
???????}
?
catch
?(Exception?e)?
{
???????????_log.error(
"
Cannot?copy?public?layouts
"
,?e);
???????}
???}
???
public
?
void
?resetLayout(HttpServletRequest?httpReq)?
throws
?SystemException,?PortalException?
{
???????String?ownerId?
=
?getOwnerId(user.getGroup().getGroupId(),?
false
);
???????LayoutLocalServiceUtil.deleteLayouts(ownerId);
???????PortletPreferencesLocalServiceUtil.deletePortletPreferences(ownerId);
???????ownerId?
=
?getOwnerId(user.getGroup().getGroupId(),?
true
);
???????LayoutLocalServiceUtil.deleteLayouts(ownerId);
???????PortletPreferencesLocalServiceUtil.deletePortletPreferences(ownerId);
???????copyDefaultUserLayout(httpReq);
???}
???
public
?Layout?copyLayout(Layout?groupDefaultLayout)?
throws
?SystemException,
???????????PortalException?
{
???????Layout?layout?
=
?LayoutLocalServiceUtil.addLayout(
???????????????userGroup.getGroupId(),?user.getUserId(),?groupDefaultLayout
??????????????????????.isPrivateLayout(),?groupDefaultLayout
???????????????????????.getParentLayoutId(),?groupDefaultLayout.getName(user
???????????????????????.getLocale()),?groupDefaultLayout.getType(),
???????????????groupDefaultLayout.isHidden(),?
null
);
???????LayoutLocalServiceUtil.updateLayout(layout.getLayoutId(),?layout
????????.getOwnerId(),?groupDefaultLayout.getTypeSettings());
???????layout?
=
?LayoutLocalServiceUtil.updateLookAndFeel(layout.getLayoutId(),
???????????????layout.getOwnerId(),?groupDefaultLayout.getThemeId(),
?
???
對我們自定的
Company來說,這肯定是不合適的,我們需要自己定義用戶登錄后,默認顯示的內容和布局。
?
???
后來在Liferay forum中,找到了一篇帖子,給了解決此種問題的解決辦法:在portlet-ext.properties中配置一個 default.user.layout.group 屬性(自定義的),用于指明默認的layout-group。在
ServicePreAction
類的擴展修改 addDefaultLayouts 操作,滿足特定的需求應用。這種擴展的方式就是,將指定layout-group拷貝給用戶第一默認的,這樣就不會再使用liferay默認的了。—— 當然這樣的方式是比較簡單的,可能在系統實施過程中,有比這更加復雜的需求。
?
新建默認的
Community
首先,通過新增一個新的
Community,命名為User_Default,并新增一個private的page與內容.
?
配置默認的
Community
首先在
ext項目的 ext-ejb目錄下,修改portal-ext.properties文件,增加如下設置:
?
default.user.layout.group
=User_Default
|
然后通過
build,將portal-ext.properties移動到 ext項目的
??? ext\servers\tomcat\webapps\ROOT\WEB-INF\classes
目錄下。
?
構造
LayoutCopy類






















































































更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
