Richfaces 4 Ajax:queue inputTextArea not queuing - jsf

I've been trying to put a queue onto a text area, and it is not cooperating. I'll list the relevant section of code below.
<h:form>
<a4j:queue requestDelay="1000" ignoreDupResponses="true"/>
<table>
<tr>
<td>
<h:outputText value="Notes:"/>
</td>
</tr>
<tr>
<td>
<h:inputTextarea value="#{MyActionBean.notes}">
<a4j:ajax event="keyup" listener="#{MyActionBean.updateNotes}"/>
</h:inputTextarea>
The notes get updated as expected, but there is no delay between requests. Is there some bug in my code, do textAreas not work for this? Any help would be appreciated.
EDIT: Just for good measure, tried the following code as well, but it didn't work either.
<h:panelGrid columns="1" width="100%">
<h:outputText value="Notes:"/>
<h:inputTextarea value="#{MyActionBean.notes}">
<a4j:ajax event="keyup" listener="#{MyActionBean.updateNotes}">
<a4j:attachQueue id="notesQueue" requestDelay="1000"/>
</a4j:ajax>
</h:inputTextArea>
</h:panelGrid>
For reference, the technology versions:
JBoss AS 7, Seam 2.3.0, Richfaces 4.2.2, JSF 2.1

For your case you need to nest a4j:attachQueue inside a4j. Try to run the code below and you'll notice that you'll get an output on the console after 15 seconds.
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<a4j:queue name='Y' requestDelay="3000" ignoreDupResponses="true"/>
<h:panelGrid columns="1" width="100%">
<h:outputText value="Notes:"/>
<h:inputTextarea value="#{MyActionBean.notes}">
<a4j:ajax event="keyup" listener="#{MyActionBean.updateNotes}">
<a4j:attachQueue requestDelay="3000"/>
</a4j:ajax>
</h:inputTextarea>
<a4j:status>
<f:facet name="start">
Please wait
</f:facet>
</a4j:status>
</h:panelGrid>
</h:form>
</h:body>
You can use this link if you need more information
UPDATE
I stripped down the code you sent to the bare minimum and I'm sorry to say that it is still working on my end with JBoss. Your issue could be somewhere else (e,g. your ajax might be failing for some reason since you told me "Please Wait" was not appearing). However, I should mention that I'm not familiar with JBoss' conversation scope so I changed it to javax.enterprise.context.SessionScoped (but I don't think that should matter because it was still working when it was requestscoped). I'm including all the code so you can test it yourself as a separate project. Also, since we are using a queue I changed the logging location from updateNotes to setReport so that I could be absolutely certain that the characters were actually being queued. When I typed "This is a test", the only output I saw was the entire String and not each character.
AssessmentCheckListAction.java
import java.io.Serializable;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
#Named(value="AssessmentChecklistAction")
#SessionScoped
public class AssessmentCheckListAction implements Serializable {
private static final long serialVersionUID = -4970638494437413924L;
private String report;
public AssessmentCheckListAction() {
}
public void updateNotes() {
//FacesContext.getCurrentInstance().getExternalContext().log(report);
//Logging the setter to make sure everything was queued
}
public String getReport() {
return report;
}
public void setReport(String report) {
FacesContext.getCurrentInstance().getExternalContext().log(report);
this.report = report;
//left blank
}
index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a4j="http://richfaces.org/a4j"
template="template.xhtml">
<ui:define name="content">
<h:form>
<a4j:queue requestDelay="3000" ignoreDupResponses="true"/>
<h:panelGrid columns="1" width="100%">
<h:outputText value="Notes:"/>
<h:inputTextarea value="#{AssessmentChecklistAction.report}">
<a4j:ajax event="keyup" listener="#{AssessmentChecklistAction.updateNotes}">
<a4j:attachQueue requestDelay="3000"/>
</a4j:ajax>
</h:inputTextarea>
<a4j:status>
<f:facet name="start">
Please wait
</f:facet>
</a4j:status>
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
template.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Cache-Control" content="no-store"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
</h:head>
<h:body>
<ui:insert name="content"/>
</h:body>
</html>

Related

templates with ui:insert-ui:composition doesn't work well

I'm trying to use jsf facelets templates, using the components ui: insert
in the template and ui: composition in which they use it, my code is something like this:
Template:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<h:outputStylesheet name="css/default.css"/>
<h:outputStylesheet name="css/cssLayout.css"/>
<h:outputStylesheet name="css/Cabecera.css"/>
<h:outputStylesheet name="css/StyleButton.css"/>
<h:outputStylesheet name="css/Progreso.css"/>
<title>Registro</title>
</h:head>
<h:body>
<div id="top">
<ui:insert name="top">Top</ui:insert>
</div>
<div>
<div id="left">
<ui:insert name="left">Left</ui:insert>
</div>
<div id="content" class="left_content">
<ui:insert name="content">Content</ui:insert>
</div>
</div>
<div id="bottom">
<ui:insert name="bottom">Bottom</ui:insert>
</div>
</h:body>
</html>
And the user:
<ui:composition template="./../Templeates/plantilla.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<ui:define name="content">
<h:outputText value="Registrar Nuevo Estudiante" style="font-size: 35px;font-weight: 100;color: #dce9f0"/>
<h:form id = "formInput">
<p:outputLabel for="codigo" value="Codigo "/>
<p:chips id="codigo" label="codigo Estudiante" value="#{RegistroAsistencia.codigos}"/>
</h:form>
<h:form id="formbutton" >
<p:commandButton value="Añadir" icon="ui-icon-star" actionListener="#{RegistroAsistencia.agregarAsesoriaEstudiante()}" update=":formInput">
<p:resetInput target=":formInput"/>
</p:commandButton>
</h:form>
</ui:define>
</ui:composition>
in the managedbean I have something like
public List<String> getCodigos() {
Logger.getLogger(ConsultaInformacionAsistentesBean.class.getName()).log(Level.SEVERE, "--->\n get codigos: "+codigos+"\n");
return codigos;
}
public void setCodigos(List<String> codigos) {
Logger.getLogger(ConsultaInformacionAsistentesBean.class.getName()).log(Level.SEVERE, "--->\nset codigos: "+codigos+"\n");
this.codigos = codigos;
}
I put the loggers to verify that the get and set methods are used respectively, when I use the "Añadir" button, the set request is never made, I verify it without using the template and in this it works:
get codes: null
set codes: null <-- When pressing the button
set codes: [2135494]
but when i try using the template:
get codigos: null
nothing <-- When pressing the button
get codigos: null
And in the agregarAsesoriaEstudiante method, codigos is null.
In conclusion, if I use the template, the "set" method of the elements is never used, so in the managedBean they are null and I am unable to get the input, try other elements of PrimeFaces different to p:chips like p: inputText but I did not find a solution , exactly the same code without using the template works perfectly, it is possible that I need something in the code or there is an error if someone knows or had similar problems I would appreciate it if I shared it.

commandLink only works with a h and p version

I'm having this really weird issue where my commandLinkonly work if I have BOTH links in the same view.
Works fine, both links:
<ui:composition template="../../template.xhtml" xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:define name="content">
<h:form>
<p:dataTable var="v" value="#{myBean.myList}">
<p:column headerText="Name">
<h:commandLink value="Go to next page" action="#{myBean.doThing(v)}" />
<p:commandLink value="Go to next page" action="#{myBean.doThing(v)}" />
</p:column>
</p:dataTable>
<p:commandButton value="Submit" ajax="false" actionListener="#{myBean.submit}" />
</h:form>
</ui:define>
</ui:composition>
But if I remove either link, it doesn't even reach the method doThing() and reloads an empty page.
My bean:
#ManagedBean(name="myBean")
#RequestScoped
public class MyBean {
private List<Object> myList = new ArrayList<>();
public MyBean() {
}
public String doThing(Object obj) {
// This never prints if I remove one of the links
System.out.println("You're doing the thing!");
return "nextView?faces-redirect=true"
}
// Getters, setters etc.
}
I'm using JSF 2.0 and GlassFish 4.0.
How can I fix this and why is it happening?
I have a commandLink in a p:dataTable in another view and it's working fine.
EDIT:
Added the complete XML for the composition part of the view. The partial is inside a template:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
<!-- css imports, titles etc -->
</h:head>
<h:body>
<ui:insert name="menu">
<ui:include src="./default/content.xhtml" />
</ui:insert>
</h:body>
</html>

Viewscoped Managed Bean recreates on every request using ui:composition (Mojarra 2.2.4)

I'm trying to understand why a viewscoped view is recreating on every ajax call.
I have a test case, and it's working fine without composition templating.
I find questions that seem similar to my problem but the solutions don't work for me, like setting javax.faces.PARTIAL_STATE_SAVING to false or javax.faces.STATE_SAVING_METHOD to client.
Here's a sample:
page.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:body>
<h:form id="pageForm">
<p:commandButton
value="Choose an option..."
actionListener="#{pageController.handleOptionChoose}"
update="selectedOption"
/>
<br/>
<h:panelGrid columns="2" cellpadding="3">
<p:outputLabel for="selectedOption" value="Selected option: "/>
<p:outputLabel id="selectedOption" value="#{pageController.selectedOption}"/>
</h:panelGrid>
<br/><br/>
<p:commandButton
value="Edit option"
actionListener="#{pageController.doAnythingWithTheOption}"
update="editedOption"
/>
<br/>
<h:panelGrid columns="2" cellpadding="3">
<p:outputLabel for="editedOption" value="Edited option: "/>
<p:outputLabel id="editedOption" value="#{pageController.editedOption}"/>
</h:panelGrid>
</h:form>
<p:dialog
id="dialogOption_Dialog"
header="Choose an option"
widgetVar="dialogOption_Widget"
modal="true"
appendTo="#(body)"
>
<h:form id="dialogOption_Form">
<h:panelGrid columns="1">
<p:selectOneButton id="dialogOptionChoose" value="#{pageController.selectedOption}" >
<f:selectItem itemLabel="Option 1" itemValue="Option 1" />
<f:selectItem itemLabel="Option 2" itemValue="Option 2" />
<f:selectItem itemLabel="Option 3" itemValue="Option 3" />
</p:selectOneButton>
<p:spacer width="0" height="20" />
<p:commandButton
value="Done"
action="#{pageController.showOption}"
update=":pageForm:selectedOption"
oncomplete="dialogOption_Widget.hide();"
/>
</h:panelGrid>
</h:form>
</p:dialog>
</h:body>
</html>
content.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:mj="http://mojarra.dev.java.net/mojarra_ext"
xmlns:o="http://omnifaces.org/ui"
xmlns:of="http://omnifaces.org/functions">
<h:body>
<ui:composition template="/layout.xhtml">
<ui:define name="content">
<ui:include src="page.xhtml" />
</ui:define>
</ui:composition>
</h:body>
</html>
layout.xhtml
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:o="http://omnifaces.org/ui"
xmlns:of="http://omnifaces.org/functions">
<f:view contentType="text/html" transient="true">
<h:head>
<h:outputStylesheet name="theme.css" library="css" />
<f:facet name="first">
<f:metadata>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
</f:metadata>
<title>Teste</title>
<link rel="icon" type="image/png" href="resources/css/icons/favicon.ico" />
</f:facet>
</h:head>
<h:body>
<p:layout fullPage="true" >
<p:layoutUnit id="top" position="north" size="50" style="border: 2px solid Black !important;">
<!-- <ui:insert name="menubar" /> -->
</p:layoutUnit>
<p:layoutUnit id="center" position="center" style="border: 2px solid Black !important;">
<ui:insert name="content" />
</p:layoutUnit>
<p:layoutUnit id="bottom" position="south" size="60" resizable="true" collapsible="true" style="border: 2px solid Black !important;">
<!-- <ui:insert name="footer" /> -->
</p:layoutUnit>
</p:layout>
</h:body>
</f:view>
</html>
PageController.java
package com.ericsantanna.grendel.mBeans;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.primefaces.context.RequestContext;
/**
* #author Eric Sant'Anna
*
*/
#ManagedBean
#ViewScoped
public class PageController {
private String selectedOption;
private String editedOption;
public PageController() {
System.out.println("RECREATING VIEW");
}
public void showOption() {
System.out.println("Selected option number: " + selectedOption.substring(7));
}
public void doAnythingWithTheOption() {
System.out.print("Trying to a substring in the selected option: ");
editedOption = selectedOption.substring(7);
System.out.println(editedOption);
}
public void handleOptionChoose() {
RequestContext.getCurrentInstance().execute("dialogOption_Widget.show();");
}
public String getSelectedOption() {
return selectedOption;
}
public void setSelectedOption(String selectedOption) {
this.selectedOption = selectedOption;
}
public String getEditedOption() {
return editedOption;
}
public void setEditedOption(String editedOption) {
this.editedOption = editedOption;
}
}
JBoss log (setup):
17:45:29,494 INFO [org.jboss.ejb.client] (MSC service thread 1-7) JBoss EJB Client version 1.0.5.Final
17:45:29,550 INFO [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-8) Inicializando Mojarra 2.2.4 ( 20131003-1354 https://svn.java.net/svn/mojarra~svn/tags/2.2.4#12574) para o contexto '/JobSchedulerWeb'
17:45:30,344 INFO [org.hibernate.validator.util.Version] (MSC service thread 1-8) Hibernate Validator 4.2.0.Final
17:45:30,367 INFO [org.primefaces.webapp.PostConstructApplicationEventListener] (MSC service thread 1-8) Running on PrimeFaces 4.0
17:45:30,368 INFO [org.omnifaces.eventlistener.VersionLoggerEventListener] (MSC service thread 1-8) Using OmniFaces version 1.5
To reproduce this code, simply choose an option and click "Edit option" to do a substring in the backing bean, only to get a NullPointerException when using facelets templating. (Look at the console in each step)
Anyone can help?
This,
<f:view ... transient="true">
turns off JSF state saving for the current view. Essentially, this JSF view is stateless. As there's no view state, there's no means of a view scope and the logical consequence is that the view scoped bean instance can't be saved anywhere. It'll disappear in nowhere by end of the request and thus behave like a request scoped bean.
The observed symptoms are thus fully expected. If that wasn't your intent, then you need to remove the transient="true" attribute. It defaults to false.
This has completely nothing to do with templating. The <ui:composition> plays no significant role here. You'd have had exactly the same problem when merging the templates into a single template without <ui:composition>, <ui:define>, etc while keeping the same markup.
See also:
Why JSF saves the state of UI components on server?
javax.faces.application.ViewExpiredException: View could not be restored

rich:calendar does not display within ui:composition

I'm new to JSF and I'm facing this weird issue. I'm sure it's a silly mistake but I just can't seem to figure it out. Basically, when I insert rich:calendar within ui:composition it does not display. My (simplified) template is defined like this
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title></title>
</h:head>
<h:body>
<ui:insert name="content"/>
<ui:debug/>
</h:body>
</html>
My index page
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:rich="http://richfaces.org/rich">
<head>
<title></title>
</head>
<body>
<ui:composition template="/indexLayout.xhtml">
<h:outputScript library="javascript" name="common.js" target="head"/>
<ui:define name="content">
<h:form>
<h:panelGrid columns="2">
From
<rich:calendar id="pickup" onchange="#{rich:component('return')}.setValue(#{rich:component('pickup')}.getValue())"
dayDisableFunction="disablementFunction" datePattern="MMM d, yyyy" value="#{reservation.pickUp}" />
To
<rich:calendar id="return" dayDisableFunction="disablementFunction" datePattern="MMM d, yyyy" />
</h:panelGrid>
<h:commandButton value="Redisplay" />
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
If I define the index page without ui:composition it displays just fine. Please help. Thank you.
You should place your <h:outputScript /> inside the <ui:define></ui:define> since when you are using <ui:composition />, every <ui:insert /> inside the template are replaced by respective <ui:define />. Everything outside <ui:define /> is not rendered.
In your case the JavaScript function disablementFunction is not loaded so your rich:calendar doesn't work properly.
Here is how your index page should look like :
<ui:composition template="/indexLayout.xhtml">
<ui:define name="content">
<h:outputScript library="javascript" name="common.js" target="head"/>
<h:form>
<h:panelGrid columns="2">
From
<rich:calendar id="pickup" onchange="#{rich:component('return')}.setValue(#{rich:component('pickup')}.getValue())" dayDisableFunction="disablementFunction" datePattern="MMM d, yyyy" value="#{reservation.pickUp}" />
To
<rich:calendar id="return" dayDisableFunction="disablementFunction" datePattern="MMM d, yyyy" />
</h:panelGrid>
<h:commandButton value="Redisplay" />
</h:form>
</ui:define>
</ui:composition>
More info :
JSF 2 templating with Facelets example

JSF Locale Change Listener not persistent

In my WebApp I created a managed Bean that allows me to change the Locale from French to english and vice versa using Event Change Listener.
package beans;
import java.util.Locale;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
#ManagedBean
#SessionScoped
public class LocaleBean {
private Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
public Locale getLocale() {
return locale;
}
public String getLanguage() {
return locale.getLanguage();
}
public void setLanguage(String language) {
locale = new Locale(language);
FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
}
}
and in my template.xhtml:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="#{localeBean.language}"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:f="http://java.sun.com/jsf/core">
<f:view contentType="text/html" locale="#{localeBean.locale}" id="mescoca">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><ui:insert name="title"></ui:insert></title>
<h:outputStylesheet name="css/jsfcrud.css"/>
<!--<f:loadBundle var="bundle" basename="/Bundle"/> -->
</h:head>
<h:body style="font-size: small; font-family: Ubuntu,verdana;">
<h:form>
<p:panel closable="false" style="float: right;height: 50px;font-size: smaller" >
<h:panelGrid columns="2" style="text-align: center">
<h:outputText value="#{bundle.Language}"/>
<h:selectOneMenu value="#{localeBean.language}" onchange="submit()">
<f:selectItem itemValue="fr" itemLabel="Français" />
<f:selectItem itemValue="en" itemLabel="English" />
<f:selectItem itemValue="fr_FR" itemLabel="France"/>
<f:selectItem itemValue="en_US" itemLabel="US" />
</h:selectOneMenu>
</h:panelGrid>
</p:panel>
The others pages:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="/template.xhtml">
<ui:define name="title">
<h:outputText value="#{bundle.EditHistoryTitle}"></h:outputText>
</ui:define>
<ui:define name="body" >
<h:panelGroup id="messagePanel" layout="block">
<h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
</h:panelGroup>
<h:form>.....
It is working, but the problem is that the language gets back to its first value once I navigate to another page. Otherwise, When I change the language, it only affects the current page and once I move to another page, the localization bundle gets its default value in faces-config.xml
What I need is to make the language persistent through the whole session.
Does anyone have a clue plz?
You need to wrap your master template in a
<f:view locale="#{LanguageBean.localeCode}">
See also:
Localization in JSF, how to remember selected locale per session instead of per request/view - contains complete bean/view code example
The problem is that when you are setting your Locale in the valueChangeListener you are setting it on the ViewRoot which lives and dies with the current view, and not the session.
You are storing your LocaleCode in the SessionScoped managed bean so you can set the Locale in the ViewRoot for every page and this should fix your problem.

Resources