Forums de discussion

Read from Web.xml in Portlet

Geervani BS, modifié il y a 13 années.

Read from Web.xml in Portlet

Junior Member Publications: 34 Date d'inscription: 28/07/10 Publications récentes
Hello Experts,

I am using SAP JCo in liferay. So need to store some SAP related connection properties. I want to make it configurable. can we store these configuration settings in web.xml. If so How to retrieve(read) data from web.xml in the Portlet. Or what is the best way to do this.

Any help will be highly appreciated.

Thanks in advance
Sandhya
thumbnail
jelmer kuperus, modifié il y a 13 années.

RE: Read from Web.xml in Portlet

Liferay Legend Publications: 1191 Date d'inscription: 10/03/10 Publications récentes
PortletBag portletBag = PortletBagPool.get(portletId);
ServletContext servletContext = portletBag.getServletContext();
String param = servletContext.getInitParameter("paramname");
Sandhya A, modifié il y a 13 années.

RE: Read from Web.xml in Portlet

Junior Member Publications: 34 Date d'inscription: 28/07/10 Publications récentes
Thanks for replying. But its not working. Its returning null for portletBag var. I am giving portletId from ThemeDisplay. I tried this in ProcessAction method
thumbnail
jelmer kuperus, modifié il y a 13 années.

RE: Read from Web.xml in Portlet

Liferay Legend Publications: 1191 Date d'inscription: 10/03/10 Publications récentes
Afaik you cannot get a portletId from the themedisplay

what is the code you are using ? the portlet id is the value of the portlet-name element in your portlet.xml for suffixed with _WAR_manglednameofyourwar

if your war is named my-portlet-6.0.1.1 and it has a portlet with name 1 the portlet id will be

1_WAR_myportlet

so remove dashes and version strings from the war name
Sandhya A, modifié il y a 13 années.

RE: Read from Web.xml in Portlet

Junior Member Publications: 34 Date d'inscription: 28/07/10 Publications récentes
Hi,

I am using

ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
PortletDisplay portletDisplay= themeDisplay.getPortletDisplay();
String portletId= portletDisplay.getId();

PortletBag portletBag = PortletBagPool.get(portletId);
ServletContext servletContext = portletBag.getServletContext();
String param = servletContext.getInitParameter("myParam");


Based on your last reply I also tried

PortletBag portletBag = PortletBagPool.get("TimeAccount");
ServletContext servletContext = portletBag.getServletContext();
String param = servletContext.getInitParameter("contextClass");

TimeAccount is the value in <portlet-name>. But same null exception emoticon

by the way my web.xml is like this

<web-app>
...
...
<context-param>
<param-name>myParam</param-name>
<param-value>myParamValue</param-value>
</context-param>
...
...
</web-app>
thumbnail
jelmer kuperus, modifié il y a 13 années.

RE: Read from Web.xml in Portlet

Liferay Legend Publications: 1191 Date d'inscription: 10/03/10 Publications récentes
Attached is a portlet that illustrates how it works