Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Reda Zerrad
creating custom properties in a hook using LifeRay IDE
March 13, 2012 9:12 AM
Answer

Reda Zerrad

Rank: New Member

Posts: 6

Join Date: March 8, 2012

Recent Posts

Hello,

I was wondering if we're able to create our own properties inside the "portal.properties" file using a hook and access them , cause I've tried that and it didn't work for me , should I try that using an ext-plugin?

Sincerely,
Réda
Reda Zerrad
RE: creating custom properties in a hook using LifeRay IDE
March 14, 2012 4:48 AM
Answer

Reda Zerrad

Rank: New Member

Posts: 6

Join Date: March 8, 2012

Recent Posts

sounds like its not possible to create your own properties in a hook , so for whom ever what to accomplish that should try using an ext-plugin : )
Prakash Khanchandani
RE: creating custom properties in a hook using LifeRay IDE
March 14, 2012 6:07 AM
Answer

Prakash Khanchandani

Rank: Expert

Posts: 329

Join Date: February 10, 2011

Recent Posts

You can create your own properties in portal-ext.properties and can access them through a plugin portlet or hook, if that is what you are trying to achieve.

1String myProperty = PrefsPropsUtil.getString("my-custom-property");
Reda Zerrad
RE: creating custom properties in a hook using LifeRay IDE
March 14, 2012 8:47 AM
Answer

Reda Zerrad

Rank: New Member

Posts: 6

Join Date: March 8, 2012

Recent Posts

Prakash Khanchandani:
You can create your own properties in portal-ext.properties and can access them through a plugin portlet or hook, if that is what you are trying to achieve.

1String myProperty = PrefsPropsUtil.getString("my-custom-property");



you mean creating an ext-plugin with and create my own properties in portal-ext.properties and then create a separate hook to access them , that sounds like a good idea : ) thank you
David H Nebinger
RE: creating custom properties in a hook using LifeRay IDE
March 14, 2012 9:37 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11511

Join Date: September 1, 2006

Recent Posts

You do not need an EXT plugin to deploy a portal-ext.properties file.

You do not need a hook in order to access the properties.

Create a property of your own making in <tomcat>/webapps/ROOT/WEB-INF/classes/portal-ext.properties.

Then in any of your code (a hook, a portlet, whatever) you can use Prakash's code to get that property value.
Sandor Nemeth
RE: creating custom properties in a hook using LifeRay IDE
July 20, 2012 3:23 AM
Answer

Sandor Nemeth

Rank: New Member

Posts: 3

Join Date: March 2, 2012

Recent Posts

Hi David!

I think my question corresponds to this thread, but if you think it should be ask in a separate thread, sorry for hitchhike this thread!

So i managed to get custom properties in my hook project from the portal-ext.properties according to your tip. But is it possible to place properties file into hook project and using properties from there? Similarly like in portlet plugin project where you can place resource-bundle tag into portlet.xml file and use that properties file from portlet code. I can't find in hook.dtd any possibility for resource bundle.

Thanks in advance!

s.
DarshanKumar N Bhatia
RE: creating custom properties in a hook using LifeRay IDE
July 20, 2012 4:49 AM
Answer

DarshanKumar N Bhatia

Rank: Junior Member

Posts: 85

Join Date: March 2, 2010

Recent Posts

Hi...

1) Simple way to define ur custom property in portal-ext.properties file is :

edit portal-ext.properties file directly (stop tomcat/liferay if it is running.)
For Example : custom.college.name = "BINGO"

2) ( Optional one ) Create Interface :


public interface MyPropsKeys {
public static final String CUSTOM_COLLEGE_NAME = "custom.college.name";
}

3) Now u can access this cutom-property in Java file using :
String customLanding=PropsUtil.get(MyPropsKeys.CUSTOM_COLLEGE_NAME);
or
String customLanding=PropsUtil.get( "custom.college.name");


There is No need to write Hook or Ext .
This property is get available to use in portlet, in theme and even Hook too.

HTH...
Sandor Nemeth
RE: creating custom properties in a hook using LifeRay IDE
July 23, 2012 3:11 AM
Answer

Sandor Nemeth

Rank: New Member

Posts: 3

Join Date: March 2, 2012

Recent Posts

Hi Darshan,

thans for quick replay! But actually i have not got problem with getting custom properties from portal-ext.properties file. It's clear according to David's post.

My question concerns the case when you must create a hook project (for some reason) and you would like to use custom properties in that hook project. One way for it to use portal-ext.properties. But portal-ext.properties is not part of hook project, instead it's part of Liferay env, and maybe you cannot access that file.

My question is that is it possible to create a hook project which contains a properties file, and in hook project use that file's custom properties?

Thanks!

s.
David H Nebinger
RE: creating custom properties in a hook using LifeRay IDE
July 23, 2012 5:23 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11511

Join Date: September 1, 2006

Recent Posts

Sandor Nemeth:
My question is that is it possible to create a hook project which contains a properties file, and in hook project use that file's custom properties?


Basically no. Hooks apply directly to the Liferay web app and run within it's context, not the hook's context. So hook code has no access to the hook's context nor whatever properties file(s) happen to be stored there.

I said 'basically no' because this is not an absolute, although from your perspective you should treat it as such.
Sandor Nemeth
RE: creating custom properties in a hook using LifeRay IDE
July 23, 2012 6:03 AM
Answer

Sandor Nemeth

Rank: New Member

Posts: 3

Join Date: March 2, 2012

Recent Posts

Thanks David a lot!