Liferay六年中持续被评为Gartner水平门户魔力象限领导者。 原因是
« 返回到 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 附件
61514 查看
平均 (1 投票)
满分为 5,平均得分为 2.0。
评论
讨论主题回复 作者 日期
Is this still a valid way to add custom... Dave Morris 2009年6月2日 下午5:57
I noticed that these properties are now stored... Dave Morris 2009年6月2日 下午6:02
I've done something to the point of: /* * *... Rob J Pontious 2009年6月4日 下午12:28
I was able to add a custom property by... Matthieu Levesque 2011年8月23日 上午8:42
In portal-ext add your own property... Mohammad Azharuddin 2013年5月31日 上午7:51
I have added property in portal-ext.properties ... Suman Chatterjee 2014年7月7日 上午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-6-2 下午5: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
在 09-6-2 下午6:02 发帖以回复 Dave Morris
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?
在 09-6-4 下午12:28 发帖以回复 Dave Morris
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);
在 11-8-23 上午8:42 发帖以回复 Rob J Pontious
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");
在 13-5-31 上午7:51 发帖以回复 Matthieu Levesque
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
在 14-7-7 上午2:58 发帖以回复 mohammad azaruddin