I'm having a problem with a JSF project. JSF Version: 2.2.13; Primefaces : 6.0; Tomcat: 7.0.42; Mojarra: 2.2.13
Whenever a request is made to the bean, the bean is restarted.
I made this small example that shows the problem.
My bean:
@ManagedBean(name = "TestMB")
@ViewScoped
public class TestMB {
private String myString = "";
public void writeMyString() {
myString = "abcd";
System.out.println("writeMyString: " + myString);
}
public void readMyString() {
System.out.println("readMyString: " + myString);
}
}
My .xhtml Page:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Test</title>
</h:head>
<h:body>
<h:form>
<h:panelGrid id = "panel" columns = "1" border = "0" cellpadding = "10" cellspacing = "1" style="width: 100%">
<p:commandButton value="Write" actionListener="#{TestMB.writeMyString}"/>
<p:commandButton value="Read" actionListener="#{TestMB.readMyString}"/>
</h:panelGrid>
</h:form>
</h:body>
</html>
My web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>glass-x</param-value>
</context-param>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
When I click the 'Write' button and then the 'Read' button this is the result:
writeMyString: abcd
readMyString:
This happens both by using '@ViewScoped' as well as '@SessionScoped'. With '@ApplicationScoped' it works. The strange thing is that this does not happen in my development environment, it only happens in the production environment.
I do not have much knowledge in this technology, so I'm kind of lost.
Thanks in advance.
------------EDIT------------
I realized that there was a different property in the tomcat production environment for my development environment. In the file config.properties, I put apjSecure=false and it worked.