JavaEE - ManagedBean没有获取值

时间:2016-01-05 11:08:18

标签: jsf managed-bean

我正在为大学做一个软件练习,而我正在尝试创建一个登录表单,但是托管bean似乎没有收到用户和密码值。

以下是观点:     

    <ui:define name="content">
      <h:form align="center" bgcolor="#E1E1E1"> 
        <h:outputText value="Correu electrònic:  "/>
        <h:inputText id = "email" value="#{login.email}" required="true"/> 
        <br/><br/>
        <h:outputText value="Contrasenya:  "/>
        <h:inputText type="password" id = "password" value="#{login.password}" required="true"/> 
        <br/><br/>
        <h:commandButton value="Login" immediate ="true" action="#{login.login}"/>
      </h:form>     
    </ui:define>

这是我的ManagedBean:

package managedbean;

import java.io.Serializable;

import ejb.UserFacadeRemote;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

@ManagedBean(name = "login")
@SessionScoped
public class LoginMBean implements Serializable{

    private static final long serialVersionUID = 1L;    

    @EJB

    private UserFacadeRemote userRemote;

    private String password;
    private String email;

    public LoginMBean() throws Exception { }

    public String getPassword() {
        return password;
    }

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

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String login() throws Exception {
        System.out.println("User 1 - " + this.email + " P - " + this.password);
    }

当我按下登录按钮时,控制台中的答案是:

11:58:45,997 INFO [stdout](http-localhost-127.0.0.1-8080-3)用户1 - null P - null

0 个答案:

没有答案