0

I am new to JSF and I've read through several tutorials, however, for some reason when I try to transfer data from a form to another page, it returns null.

This is the bean

package stateless;

import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.Dependent;


@Named(value = "jsfbean")
@Dependent
public class jsfbean {

@EJB
private MyuserFacadeRemote myuserFacade;

private String username;
private String password;
private String message;
/**
 * Creates a new instance of jsfbean
 */
public jsfbean() {
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public String getMessage() {
    return "Hello "+ username;
}

public void setMessage(String message) {
    this.message = message;
}
}

This is the main page

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
    <title>Index</title>
</h:head>
<h:body>
    <h:form>
        <p>Login</p>
        <h:inputText value="#{jsfbean.username}"/>
        <h:commandButton action="result" value="Results Page"/>
    </h:form>
</h:body>
</html>

On the result page, the only thing that is there is #{jsfbean.message} Hope someone can help

JianYA
  • 2,750
  • 8
  • 60
  • 136

1 Answers1

0

I think @dependent scope could not work. Try session scope.

Lars Michaelis
  • 559
  • 2
  • 6
  • 11
  • whats the difference between each scope?? – JianYA Apr 18 '16 at 16:20
  • When a Unified EL expression in a JSF or JSP page that refers to the bean by its EL name is evaluated, at most one instance of the bean is instantiated. This instance exists to service just a single evaluation of the EL expression. It is reused if the bean EL name appears multiple times in the EL expression, but is never reused when the EL expression is evaluated again, or when another EL expression is evaluated. – Lars Michaelis Apr 19 '16 at 07:23
  • See https://docs.jboss.org/cdi/api/1.0/javax/enterprise/context/Dependent.html – Lars Michaelis Apr 19 '16 at 07:23