问题
I have a portlet in which i want to set title as the different page loads. The solution i found is using PortalUtil.addPageTitle (String myTitle, HttpServletRequest request)
as mentioned here. But i don't know here and how to use it. Any idea? Any alternative will also work as long as it is not javascript approach.
回答1:
PortalUtil.addPageTitle (String myTitle, HttpServletRequest request)
sets the title of the page (htmlTitle). not the title of the portlet.
There are two approcahes to solve this,
Liferay provides an option to set the title via portlet preferences.
PortletPreferences portletSetup = PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, instanceId);
Locale locale = new Locale("en", "US"); //straight to the point
portletSetup.setValue("portlet-setup-title-" + LocaleUtil.toLanguageId(locale), title);
portletSetup.setValue("portlet-setup-use-custom-title", "true");
portletSetup.store();
In your portlet class, you set the title to the response.
response.setTitle("Dynamic Title");
If you want to change the title of the page, you can set that in two different ways. you can add unique title per page using the control panel
the other method is through programming (Below is the psuedocode).
layout.setHtmlTitle("dynamic Title");
layoutLocalserviceUtil.updateLayout(layout);
来源:https://stackoverflow.com/questions/14133663/liferay-set-title-name-for-view-pages