我正在做我的第一个 JSF 应用程序并且我正在实现登录页面。但是当我提交带有登录名和密码的表单时遇到问题。我使用 JSF 2.0
我有以下表格:
<h:form>
<h:panelGrid columns="2">
<p:outputLabel for="txt_login" value="Login" />
<p:inputText id="txt_login" value="#{loginBean.login}"/>
<p:outputLabel for="txt_senha" value="Senha" />
<p:inputText id="txt_senha" value="#{loginBean.senha}"/>
</h:panelGrid>
<h:panelGrid columns="2">
<p:commandButton value="Login" action="#{loginBean.efetuaLogin}" />
<p:commandButton value="Cancelar" action="cancelar" />
</h:panelGrid>
</h:form>
和 ManagedBean:
@ManagedBean
public class LoginBean {
private String login;
private String senha;
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
System.out.println("SENHA = " + this.getSenha());
this.senha = senha;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
System.out.println("USER = " + this.getLogin());
this.login = login;
}
public String efetuaLogin() {
Usuario user = new Usuario(this.login, this.senha);
System.out.println("USER = " + this.getLogin() + " SENHA = " + this.getSenha());
UsuarioController.getInstance().save(user);
return "sucesso";
}
public String cadastar() {
Usuario user = new Usuario(this.login, this.senha);
System.out.println("USER = " + this.login + " SENHA = " + this.senha);
UsuarioController.getInstance().save(user);
return "sucesso";
}
}
当提交这些表单时,我的托管 bean 将传递 null。为什么会发生?