Sunday 29 January 2012

Customising Liferay's My account portlet

It was needed to allow user change their profile by accessing some user page with My account portlet.
    Because of My account portlet is system one you can't add it to pages simply, but by overriding some properties under ext-plugin you will be able to put it on the page.


To do this you need:
  1. Override My account portlet preferences under liferay-portlet-ext.xml in your ext-plugin:
                    
             
                2
                false
             
    
    portlet-name = 2 - is id of Liferay's My account portlet.
  2. Override My account portlet preferences under portlet-ext.xml in your ext-plugin with:
                    
            
               2
               My Account
               ...
               
                 view-action
                 /my_account/edit_user
               
               ...
            
    
After deploying ext-plugin you will find My account portlet under Add - More - Tool menu and it will be able to page placement.

Second task was changing view of form page with user's fields. User should see only few fields without right panel with different categories of his profile.
    To hide categories panel you can change liferay-ui:form-navigator taglib's page /html/taglib/ui/form_navigator/page.jsp by using hook-plugin.
    At this jsp find:
 
and change it with:
<%  String portletName = portletDisplay.getPortletName(); %>
style="display:none" class="lfr-component form-navigator">

After deploying hook panel will be hidden.
Beware this change will affect my account portlet under control panel, but changing user properties under user mangemnet will not be affected.

Third what I wanted to do is to add my own viev for changing user fields.
    To do it I checked portal.properties and have found next:

#
# Input a list of sections that will be included as part of the user form
# when updating a user in the My Account portlet.
#
users.form.my.account.main=details,password,organizations,sites,user-groups,roles,personal-site,categorization
users.form.my.account.identification=addresses,phone-numbers,additional-email-addresses,websites,instant-messenger,social-network,sms,open-id
users.form.my.account.miscellaneous=announcements,display-settings,comments,custom-fields
by this property you can configure wich items will be shown in right panel.

Also you can easely add youre own viwes to Liferay's categories panel:
  1. Add name of the view to section where it should be placed
    #
    # Input a list of sections that will be included as part of the user form
    # when updating a user in the My Account portlet.
    #
    users.form.my.account.main=custom-view
    users.form.my.account.identification=
    users.form.my.account.miscellaneous=
    
  2. Add jsp page to /html/portlet/users_admin/user/custom_view.jsp for version 6.1, for lower version add /html/portlet/enterprise_admin/user/custom_view.jsp
  3. Add translation to language properties: custom-view=Custom view
After that you will be able to put those field to jsp which is needed.

1 comment:

  1. Hi,

    I want to add My account portlet under Add - More - Tool menu. I tried your solution but it is not working, i got below error when i m trying to do the same. Please find below error.

    com.liferay.portal.NoSuchResourceActionException: 2#ADD_TO_PAGE

    Kindly help

    Thanks,
    Vijay

    ReplyDelete