Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Øyvind Askedal
Portlet reading from a custom properties file
15 de Agosto de 2012 00:41
Resposta

Øyvind Askedal

Ranking: New Member

Mensagens: 2

Data de entrada: 21 de Maio de 2012

Mensagens recentes

Hi,

I'm new in Liferay and I'm trying to create a portlet that reads menu items from a properties file, as the menu items are most likely going to be all static datas. The portlet should then be integrated at the bottom in my theme. Any good tutorials or links on where to start?
My first guess was this, but I only get the message
\WEB-INF\classes\bottomMenu.properties (The system cannot find the path specified)

so I guess this is not the way?

Here is my code in the doView method of my portlet:

 1public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
 2       
 3        Properties properties = new Properties();
 4        String value="";
 5        try {
 6            String url = "/WEB-INF/classes/bottomMenu.properties";
 7            properties.load(new FileInputStream(url));
 8            
 9            for(String key : properties.stringPropertyNames()) {
10                value = properties.getProperty(key);
11                System.out.println(key + "=>" + value);
12            }
13            
14            renderRequest.setAttribute("url",value);
15            
16       
17        } catch (IOException e1) {
18            
19            System.out.println(e1);
20            
21        }
22       
23        //this.include(this.viewJSP, renderRequest, renderResponse);
24        super.doView(renderRequest, renderResponse);
25       
26    }
Vilmos Papp
RE: Portlet reading from a custom properties file
15 de Agosto de 2012 02:41
Resposta

Vilmos Papp

LIFERAY STAFF

Ranking: Liferay Master

Mensagens: 521

Data de entrada: 21 de Outubro de 2010

Mensagens recentes

Hi,

Please check the Mail Portlet, there you can see how to use portlet.properties for portlet specific property settings.

Regards,
Vilmos
Samuel Kong
RE: Portlet reading from a custom properties file
15 de Agosto de 2012 02:51
Resposta

Samuel Kong

LIFERAY STAFF

Ranking: Liferay Legend

Mensagens: 1476

Data de entrada: 10 de Março de 2008

Mensagens recentes

Probably a class loader issue. To avoid dealing with the class loader issue, just name your properties file, portlet.properties and place the file at /docroot/WEB-INF/src/portlet.properties Then you can just use the below code tor read your properties file:

1String value = com.liferay.util.portlet.PortletProps.get("my.property.key");
Hitoshi Ozawa
RE: Portlet reading from a custom properties file
15 de Agosto de 2012 04:18
Resposta

Hitoshi Ozawa

Ranking: Liferay Legend

Mensagens: 7949

Data de entrada: 23 de Março de 2010

Mensagens recentes

Following page contains a sample:

http://www.liferay.com/community/wiki/-/wiki/Main/How+to+add+a+Properties+File+to+a+Portlet
Ram A
RE: Portlet reading from a custom properties file
30 de Janeiro de 2013 07:36
Resposta

Ram A

Ranking: Junior Member

Mensagens: 76

Data de entrada: 16 de Janeiro de 2013

Mensagens recentes

Hi ,

Can anyone help me how to read the pom.properties file inside my portlets.
path : target\maven-archiver\pom.properties.

i think i have to read it as reading a file from classpath.



Thanks in advance
Ram A
David H Nebinger
RE: Portlet reading from a custom properties file
30 de Janeiro de 2013 10:56
Resposta

David H Nebinger

Community Moderator

Ranking: Liferay Legend

Mensagens: 11464

Data de entrada: 1 de Setembro de 2006

Mensagens recentes

ClassLoader.getResourceAsStream("target/maven-archiver/pom.properties") to get the input stream. Route to a new Properties instance (has loading from input stream), where you can fetch the property.
K. Behrends
RE: Portlet reading from a custom properties file
20 de Fevereiro de 2015 05:40
Resposta

K. Behrends

Ranking: New Member

Mensagens: 4

Data de entrada: 6 de Janeiro de 2012

Mensagens recentes

You can read the base.path property to get the path to the portlet.properties file, and then work your way to your custom file.

Properties props = loadProperties(); //liferay API


String basepath = props.getProperty("base.path");
Properties customprops = readPropfile(basepath);


and then

public Properties readPropfile(String defaultpropfilename){

Properties props = new Properties();
InputStream is = null;
File file = new File(defaultpropfilename);
String parentDirName = file.getParent();

// try loading from the same directory
try {
File f = new File(parentDirName, "bottomMenu.properties");
is = new FileInputStream( f );
props.load( is );
is.close();
}
catch ( Exception e ) { is = null;
e.printStackTrace();

}

return props;

}
Tariqul Islam
RE: Portlet reading from a custom properties file
27 de Fevereiro de 2015 05:49
Resposta

Tariqul Islam

Ranking: New Member

Mensagens: 15

Data de entrada: 27 de Janeiro de 2013

Mensagens recentes