Additional research on liferay portal (4): Modify the default layout and content after User Logon

Source: Internet
Author: User
After the first login, liferay generates a default private homepage layout for the user. In earlier versions of liferay, you can configure the default group layout on the system administrator management interface. However, this function is not available in version 4.1, so by default, newly registered users first see the same private place content after login, these contents are provided by liferay.

This is definitely not suitable for our custom company. We need to define the content and layout displayed by default after user logon.

Later in liferay forum, I found a post to give a solution to this problem: configure a default in the portlet-ext.properties. user. layout. the Group attribute (custom) is used to specify the default Layout-group. Modify the adddefalalayouts operation in the servicepreaction class to meet specific requirements. The extension method is to copy the specified layout-group to the user's first default, so that the liferay default is no longer used. -- Of course, this method is relatively simple, and there may be more complicated requirements in the system implementation process.

 

Create a default communityFirst, add a new Community named user_default and add a private page and content. Configure the default communityFirst in the ext-EJB directory of the ext project, modify the portal-ext.properties file and add the following settings:
Default. User. layout. Group = user_default

Then, move the portal-ext.properties to the EXT/servers/tomcat/webapps/root/WEB-INF/classes directory of the ext project through build. Construct the layoutcopy classPublic class layoutcopy ...{

Private Static log _ log = logfactory. getlog (layoutcopy. Class );

Private 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 = 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 );

Copydefauseruserlayout (httpreq );
}

Public layout copylayout (layout groupdefalalayout) throws systemexception,
Portalexception ...{
Layout layout = layoutlocalserviceutil. addlayout (
Usergroup. getgroupid (), user. getuserid (), groupdefalalayout
. Isprivatelayout (), groupdefalalayout
. Getparentlayoutid (), groupdefaultlayout. getname (User
. Getlocale (), groupdefalalayout. GetType (),
Groupdefalalayout. ishidden (), null );

Layoutlocalserviceutil. updatelayout (layout. getlayoutid (), Layout
. Getownerid (), groupdefaultlayout. gettypesettings ());
Layout = layoutlocalserviceutil. updatelookandfeel (layout. getlayoutid (),
Layout. getownerid (), groupdefalalayout. getthemeid (),
Groupdefalalayout. getcolorschemeid ());

// Layoutmapping. Put (groupdefaultlayout. getprimarykey (),
// Layout. getprimarykey ());

Return layout;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.