« Wiki - Pending... に戻る

Adding Custom Properties

タグ: customization

This article is pending deletion for not enough information. For more information, please see Wiki - Pending Deletion.

Introduction #

This guide explains how to do add your own custom properties in Liferay. It attempts to leverage the Liferay properties infrastructure to maintain consistency.

Requirements #

The only prerequisite to customizing your own set of properties is that the Liferay development environment is setup (see the topic Setting up the Extension Environment).

How it works #

This is a custom deployment -- there are however other ways of doing this.

  • Subclass com.liferay.portal.util.PropsUtil and define your custom properties. For example we created a class com.liferay.portal.util.USCPropsUtil:
package com.liferay.portal.util;
import com.liferay.portal.util.PropsUtil;
/* *
* This class extends the PropsUtil class for additional properties needed. *
*/
public class USCPropsUtil extends PropsUtil {
        // Shibboleth Authentication properties        public static final String USC_AUTH_SHIB_UID = "usc.auth.shibboleth.uid";        public static final String USC_AUTH_SHIB_USCOWNERPVID = "usc.auth.shibboleth.uscownerpvid";        public static final String USC_AUTH_SHIB_MAIL = "usc.auth.shibboleth.mail";        public static final String USC_AUTH_SHIB_DISPLAYNAME = "usc.auth.shibboleth.displayname";//

// Shibboleth User Group properties }}}}//

*Add/map the custom properties to /ext-impl/classes/portal-ext.properties.  For example we created a section within portal-ext.properties for our custom properties:

{{{
##
## USC specific properties 
##

    #
    # Shibboleth Authentication properties.  
    # These define the HTTP header variables that will contain the user attributes.
    # All variables must be populated otherwise the user cannot successfully authenticate.
    #
    usc.auth.shibboleth.uid=shib-person-uid
    usc.auth.shibboleth.uscownerpvid=shib-person-uscownerpvid
    usc.auth.shibboleth.mail=shib-person-mail
    usc.auth.shibboleth.displayname=shib-person-displayname
  • Use it in your classes. For example we read our properties within our custom AutoLogin module. The value returned can optionally be passed through one of the methods in com.liferay.util.PrefPropsUtil to translate into various data types:
    try {
        companyId = PortalUtil.getCompany(req).getCompanyId();

        userScreenName = req.getHeader(PrefsPropsUtil.getString(companyId,USCPropsUtil.USC_AUTH_SHIB_UID));
        uscpvid = req.getHeader(PrefsPropsUtil.getString(companyId,USCPropsUtil.USC_AUTH_SHIB_USCOWNERPVID));
        mail = req.getHeader(PrefsPropsUtil.getString(companyId,USCPropsUtil.USC_AUTH_SHIB_MAIL));
        displayName = req.getHeader(PrefsPropsUtil.getString(companyId,USCPropsUtil.USC_AUTH_SHIB_DISPLAYNAME));
    }
    catch (Exception e) {
               _log.error(StackTraceUtil.getStackTrace(e));
    }

Notes #

  • This has not been tested with Portlets!
  • This has been tested with Liferay Core

Related Articles #

Development in the ext environment

0 添付ファイル
71226 参照数
平均 (1 投票)
平均評価は2.0星中の5です。
コメント
コメント 作成者 日時
Is this still a valid way to add custom... Dave Morris 2009/06/02 17:57
I noticed that these properties are now stored... Dave Morris 2009/06/02 18:02
I've done something to the point of: /* * *... Rob J Pontious 2009/06/04 12:28
I was able to add a custom property by... Matthieu Levesque 2011/08/23 8:42
In portal-ext add your own property... Mohammad Azharuddin 2013/05/31 7:51
I have added property in portal-ext.properties ... Suman Chatterjee 2014/07/07 2:58

Is this still a valid way to add custom properties in the ext environment? I'm getting this error when I try to follow this pattern:

Implicit super constructor PropsUtil() is not visible for default constructor. Must define an explicit constructor

This is because the PropsUtil constructor is private. Is this correct? What is the proper way to extend the portal-ext.properties file in Liferay 5.2.2?
投稿日時:09/06/02 17:57
I noticed that these properties are now stored in PropsKeys.java

Maybe this is the correct class to extend. Can anyone confirm this? If so, I will update this wiki page, or create a new version.

Thanks for the help,

Dave Morris
Dave Morrisへのコメント。投稿日時:09/06/02 18:02
I've done something to the point of:

/*
*
* This class extends the PropsUtil class for additional properties needed.
*
*/
public class CustomPropsUtil extends PropsValues {

// Default phases
public static final String DEFAULT_VAR = PropsUtil.get("default.var");
}

In portal-ext.properties I've added a default.var with a value, but when I call as:

String defaultPhasesString = CustomPropsUtil.DEFAULT_PHASES;

I get a value of null returned. So I'm missing something somehow. But maybe that'll help you Dave?
Dave Morrisへのコメント。投稿日時:09/06/04 12:28
I was able to add a custom property by implementing the com.liferay.portal.kernel.util.PropsKeys and declaring final static string vars.

public class WebPortalKeys implements PropsKeys {
public static final String LCC_PORTAL_GRP_EMP = "lcc.portal.group.emp";
public static final String LCC_PORTAL_GRP_ETU = "lcc.portal.group.etu";

public static final String LCC_PORTAL_PORTAL_COMMUNITY_EMP = "lcc.portal.community.emp";
public static final String LCC_PORTAL_PORTAL_COMMUNITY_ETU = "lcc.portal.community.etu";
}

Using this call I was able to retreive the value "gr-emp" set in my portal-ext.properties:
PrefsPropsUtil.getString(companyId, WebPortalKeys.LCC_PORTAL_GRP_EMP);
Rob J Pontiousへのコメント。投稿日時:11/08/23 8:42
In portal-ext add your own property
showroom.city.names=bangalore,mangalore,chennai


And in Java use below code to get the values
import com.liferay.portal.kernel.util.PropsUtil;
String type = PropsUtil.get("showroom.city.names");
Matthieu Levesqueへのコメント。投稿日時:13/05/31 7:51
I have added property in portal-ext.properties

endpoint_url=http\://myip\:8180/

here myip is a end point url

but when i try to fetch the same in my ext impl class the value is coming as null
String strEndPointURL = PropsUtil.get("endpoint_url");
everything was working fine before but since i have made update to the file and redeployed it is not working.
As informed in other posts i have deployed and restarted my jboss server twice once for the extensive environment to load and second for other plugins to load but still with no success, any help would be appreciated
mohammad azaruddinへのコメント。投稿日時:14/07/07 2:58