Forums de discussion

liferay 7 JSF localization problem

M T, modifié il y a 7 années.

liferay 7 JSF localization problem

New Member Publications: 11 Date d'inscription: 02/11/16 Publications récentes
Hi Community,

I've a nasty problem getting localization inside a JSF protlet to work correctly.
I was trying to get the hook method running but with partial success...

This is my liferay-hook.xml:
<!--?xml version="1.0"?-->


<hook>
	<language-properties>content/Language_en_US.properties</language-properties>
	<language-properties>content/Language_de_DE.properties</language-properties>
	<language-properties>content/Language_fr_FR.properties</language-properties>
</hook>


I placed the resource files inside Eclipse IDE under the folder:
src/main/resources/content/ which then get deploed to WEB-INF/classes/content

This is ok so far. The strange behaviour is as follows:

-- When I alter the language settings on the front end e.g. via the language selector protlet only the contents of Language_de_DE.properties are shown, no matter which language I choose.

I've restarted Liferay 7 serveral times, cleard browser chache, removed and added my "my_jsfportlet" several times. The outcome is still the same.
One important note to mention - The Language_de_DE.properties is reflecting changes, so e.g. when I alter key/vlaues inside of this file they are shon correctly on the front end.

Here's my view.xhtml from "my_jsfportlet":

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:alloy="http://liferay.com/faces/alloy" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html">

	<h:head>
		<h:outputstylesheet library="css" name="main.css" />
	</h:head>
	<alloy:form>
		<h:messages globalOnly="true" />
		<alloy:outputlabel value="#{i18n['enter-name']}" />
		<h:inputtext value="#{backingBean.name}" />
		<h:commandbutton actionlistener="#{backingBean.submit}" value="#{i18n['submit']}">
			<f:ajax execute="@form" render="@form" />
		</h:commandbutton>
		<br>
		<h:outputtext value="Hello #{backingBean.name}" />
	</alloy:form>
	<!-- Example#3: Styling via value attribute (Note: This can only be used if the component does not have any -->
	<!-- children and the component does not specify an image) -->
	<alloy:form>
		<alloy:button value="1234" outcome="view2" />
	</alloy:form>
	<alloy:outputlabel>Current Locale: #{backingBean.locale}</alloy:outputlabel>

</ui:composition>


I also tried to identify the current locale setting inside my backing bean. The loacle is correctly set whenever I toggle the language selector protlet.

Here's the "BackingBean":
@RequestScoped
@ManagedBean
public class BackingBean {
	
	
	private static Logger logger = Logger.getLogger( BackingBean.class );
	
	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void submit(ActionEvent actionEvent) {
		FacesContextHelperUtil.addGlobalSuccessInfoMessage();
	}

	public void PageCodeBase() {
	         FacesContext.getCurrentInstance().getViewRoot().setLocale(getLocale());
	     }

	public Locale getLocale() {
		Locale loc = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
		logger.debug("Method: getLocale() called....returning: " + loc);
		return loc;
	}

}


Any hint heavily appreciated!
CU
thumbnail
Juan Gonzalez, modifié il y a 7 années.

RE: liferay 7 JSF localization problem

Liferay Legend Publications: 3089 Date d'inscription: 28/10/08 Publications récentes
Hi, hmmm this sounds weird if it just works for a locale.

Which Liferay 7 GA version are you using?

Additionally, which Liferay Faces versions are you using?

To make our tests faster, can you provide a sample project to reproduce?

Thanks!
M T, modifié il y a 7 années.

RE: liferay 7 JSF localization problem

New Member Publications: 11 Date d'inscription: 02/11/16 Publications récentes
Hi Juan,

thanks for your reply.
My Liferay verison is 7.0-GA3.

See pom inside my_jsfportlet for versions.
I've added my eclipse "micro" project below.

Thanks.
thumbnail
Juan Gonzalez, modifié il y a 7 années.

RE: liferay 7 JSF localization problem

Liferay Legend Publications: 3089 Date d'inscription: 28/10/08 Publications récentes
Hi M.

Thanks for your sample portlet.

Can you try adding liferay-faces-portal dependency to your project (3.0.0) and retest?
M T, modifié il y a 7 années.

RE: liferay 7 JSF localization problem

New Member Publications: 11 Date d'inscription: 02/11/16 Publications récentes
Hi Juan,

thanks four your feedback.
I can't find the right version.

Is it :
com.liferay.faces
liferay-faces-portal
3.0.0-ga1


I can't find version 3.0.0

3.0.0-ga1 as well as any higher version number leads to compilation errors.
thumbnail
Juan Gonzalez, modifié il y a 7 années.

RE: liferay 7 JSF localization problem

Liferay Legend Publications: 3089 Date d'inscription: 28/10/08 Publications récentes
M T:
Hi Juan,

thanks four your feedback.
I can't find the right version.

Is it :
com.liferay.faces
liferay-faces-portal
3.0.0-ga1


I can't find version 3.0.0

3.0.0-ga1 as well as any higher version number leads to compilation errors.


Right groupId is this one:

<dependency>
			<groupid>com.liferay.faces</groupid>
			<artifactid>com.liferay.faces.portal</artifactid>
			<version>3.0.0</version>
		</dependency>
M T, modifié il y a 7 années.

RE: liferay 7 JSF localization problem

New Member Publications: 11 Date d'inscription: 02/11/16 Publications récentes
Perfect Juan! emoticon It works!

Can you elaborate what was actually missing here?
thumbnail
Kyle Joseph Stiemann, modifié il y a 7 années.

RE: liferay 7 JSF localization problem

Liferay Master Publications: 760 Date d'inscription: 14/01/13 Publications récentes
Hi M T,
Just wanted to let you know that we've created FACES-2959 so that you won't need to include Liferay Faces Portal (unless you want to emoticon) in the future. Basically, this was a feature of the Liferay Faces Portal jar, but it probably fits better into the Bridge.

Thanks for bringing this to our attention, and thanks for using Liferay Faces!

- Kyle
M T, modifié il y a 7 années.

RE: liferay 7 JSF localization problem

New Member Publications: 11 Date d'inscription: 02/11/16 Publications récentes
Hi Kyle,

thanks for clarification.
I appreciate your efforts.

MT
thumbnail
Juan Gonzalez, modifié il y a 7 années.

RE: liferay 7 JSF localization problem

Liferay Legend Publications: 3089 Date d'inscription: 28/10/08 Publications récentes
M T:
Perfect Juan! emoticon It works!

Can you elaborate what was actually missing here?


There is a PhaseListener in liferay-faces-portal to set the Locale from Liferay (themeDisplay) into JSF ViewRoot: https://github.com/liferay/liferay-faces-portal/blob/master/portal/src/main/java/com/liferay/faces/portal/lifecycle/LiferayLocalePhaseListener.java. This way everything is done automagically and transparent for those two worlds.

As Kyle said, this is going to be moved to bridge-ext, so people doesn't have to include liferay-faces-portal into their projects unless they use some of the available components there.