Forums de discussion
Best practices for accessing context parameters from beans
Christophe Noel, modifié il y a 10 années.
Best practices for accessing context parameters from beans
Junior Member Publications: 99 Date d'inscription: 28/09/12 Publications récentes
Hello,
It's been some time that, from my Managed Bean, I have been using the same JSF approach in order to access parameters such as portletId, portletInstanceId, groupId, etc.
I would like to know if there is a better and shorter way for accessing this data ? (because it seems quite tricky isn't it ?)
My current approach is as follow:
Get ThemeDisplay :
Get Portlet Id:
Thanks for your advice.
Christophe.
It's been some time that, from my Managed Bean, I have been using the same JSF approach in order to access parameters such as portletId, portletInstanceId, groupId, etc.
I would like to know if there is a better and shorter way for accessing this data ? (because it seems quite tricky isn't it ?)
My current approach is as follow:
Get ThemeDisplay :
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); // or LiferayFacesContext works too
ThemeDisplay themeDisplay = (ThemeDisplay) context.getRequestMap().get(WebKeys.THEME_DISPLAY);
Get Portlet Id:
String portletId = themeDisplay.getPortletDisplay().getId();
Thanks for your advice.
Christophe.
David H Nebinger, modifié il y a 10 années.
RE: Best practices for accessing context parameters from beans
Liferay Legend Publications: 14916 Date d'inscription: 02/09/06 Publications récentes
Best practice - don't do it.
Seriously, if you've made yourself dependent upon the context params, especially the portlet id, I think you've done something wrong. I've written many portlets in jsp/struts, jsf, and vaadin and not one has been dependent upon context params, and never would I base dependence on the portlet id.
Seriously, if you've made yourself dependent upon the context params, especially the portlet id, I think you've done something wrong. I've written many portlets in jsp/struts, jsf, and vaadin and not one has been dependent upon context params, and never would I base dependence on the portlet id.
Christophe Noel, modifié il y a 10 années.
RE: Best practices for accessing context parameters from beans
Junior Member Publications: 99 Date d'inscription: 28/09/12 Publications récentes
What do you mean ?
When developing Liferay services, I generally use the serviceContext (to allow permissions on specific groupId, companyId).
When setting preferences per portlet instance, I would need the portlet instance Id.
So what am I'm doing wrong ?
When developing Liferay services, I generally use the serviceContext (to allow permissions on specific groupId, companyId).
When setting preferences per portlet instance, I would need the portlet instance Id.
So what am I'm doing wrong ?
Vernon Singleton, modifié il y a 10 années.
RE: Best practices for accessing context parameters from beans
Expert Publications: 315 Date d'inscription: 14/01/13 Publications récentesChristophe Noel:
I would like to know if there is a better and shorter way for accessing this data ? (because it seems quite tricky isn't it ?)
My current approach is as follow:
Get ThemeDisplay :ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); // or LiferayFacesContext works too ThemeDisplay themeDisplay = (ThemeDisplay) context.getRequestMap().get(WebKeys.THEME_DISPLAY);
Hi Christophe,
You might like:
LiferayFacesContext.getInstance().getThemeDisplay()
There are all kinds of handy Liferay specific methods hanging off of the LiferayFacesContext.
Hope you like it.
- Vernon
David H Nebinger, modifié il y a 10 années.
RE: Best practices for accessing context parameters from beans
Liferay Legend Publications: 14916 Date d'inscription: 02/09/06 Publications récentes
portlet instance id is not used in the service context.
company and group ids are necessary if you are storing records that have company/group access limitations, but those values can be accessed through other means (I believe there's a thread local to get to these details, kinda like the PrincipalThreadLocal).
company and group ids are necessary if you are storing records that have company/group access limitations, but those values can be accessed through other means (I believe there's a thread local to get to these details, kinda like the PrincipalThreadLocal).
Christophe Noel, modifié il y a 10 années.
RE: Best practices for accessing context parameters from beans
Junior Member Publications: 99 Date d'inscription: 28/09/12 Publications récentesVernon Singleton:
Hi Christophe,
You might like:LiferayFacesContext.getInstance().getThemeDisplay()
There are all kinds of handy Liferay specific methods hanging off of the LiferayFacesContext.
Hope you like it.
- Vernon
Thanks Vernon, this is very useful to know.
Therefore, is the "portlet custom title" also simplified with Liferay Faces ? I may only get this value as follow:
ThemeDisplay themeDisplay = LiferayFacesContext.getInstance()
.getThemeDisplay();
String portletId = themeDisplay.getPortletDisplay().getId();
javax.portlet.PortletPreferences portletSetup = PortletPreferencesFactoryUtil
.getLayoutPortletSetup(themeDisplay.getLayout(), portletId);
String portletCustomTitle = themeDisplay.getPortletDisplay().getTitle();
portletCustomTitle = portletSetup.getValue("portletSetupTitle_"
+ themeDisplay.getLanguageId(), portletCustomTitle);
It seems that liferay.portlet.displayName or liferay.themeDisplay.portletDisplay.title are still not rewritten at the right time.
Thanks, Christophe.