Liferay: Set title name for view pages

自闭症网瘾萝莉.ら 提交于 2020-02-25 08:35:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!