Good time of day, there is a JSF-2 project [Netbeans 8 + JBoss as 7.1.1 + java ee 6] with two xhtml. Problem Description: When setting a value (result variable) on one page and switching to another, the set value is not saved, but if the result variable is made static, it is saved normally. In java ee newbie if you need something else hint ...
Here is the class code:
import java.io.Serializable; import javax.inject.Named; import javax.faces.bean.SessionScoped; @Named("users") @SessionScoped public class UserBean implements Serializable { private String result = ""; public String getResult() { return result; } public void setResult(String newResult) { result = newResult; } } Here is the starting 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>Welcome</title> </h:head> <h:body> <h:form> <h3>Please enter result</h3> <table> <tr> <td>Name:</td> <td><h:inputText value="#{users.result}"/></td> </tr> </table> <p><h:commandButton value="get" action="welcome" /></p> </h:form> </h:body> </html> Here is the second 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>Welcome</title> </h:head> <h:body> <h3>#{users.result}!</h3> </h:body> </html> web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" mlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>faces/index.xhtml</welcome-file> </welcome-file-list> <context-param> <param-name>javax.faces.PROJECT_STAGE</param-name> <param-value>Development</param-value> </context-param> </web-app>