In the previous tutorial Localization (l10n) in liferay we change the portlet content on the basis of locale.But what if we want to change the title of portlet.In this tutorial we localize title of portlet.We can achieve this by two ways:-
Put a key (ex-portlet_title) in your Language_xxx.properties file and get the key using default locale and than set in setTitle() method:-
Demo.java
First Method
Put a key (ex-portlet_title) in your Language_xxx.properties file and get the key using default locale and than set in setTitle() method:-
Demo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.demo; | |
import java.io.IOException; | |
import java.util.Locale; | |
import javax.portlet.PortletConfig; | |
import javax.portlet.PortletException; | |
import javax.portlet.RenderRequest; | |
import javax.portlet.RenderResponse; | |
import com.liferay.portal.kernel.language.LanguageUtil; | |
import com.liferay.portal.kernel.util.JavaConstants; | |
import com.liferay.util.bridges.mvc.MVCPortlet; | |
public class Demo extends MVCPortlet { | |
@Override | |
public void doView(RenderRequest renderRequest,RenderResponse renderResponse) throws IOException, PortletException { | |
Locale defaultLocale = Locale.getDefault(); | |
PortletConfig portletConfig = (PortletConfig) renderRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG); | |
String title = LanguageUtil.get(portletConfig, defaultLocale, "portlet_title"); | |
renderResponse.setTitle(title); | |
super.doView(renderRequest, renderResponse); | |
} | |
} |
Second Method
This is pretty simple just put the key as javax.portlet.title and that's it. No need to do anything in Controller. Ex:-
javax.portlet.title = MyCustomTitleAgain
Output:-
Output:-
You can also check out the video for this:-
Hope this will Help....
You can Download Source code from Localize portlet title in Liferay.
Related Post:-
You can Download Source code from Localize portlet title in Liferay.
Related Post:-
No comments:
Post a Comment