jsf-如何在托管bean中获取inputText值?

jsf-如何在托管bean中获取inputText值?,jsf,jsf-2,Jsf,Jsf 2,我有一个inputText,我想从中检索值,但它似乎没有在我的bean类中调用setter方法这是我的bean类: import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.p

我有一个
inputText
,我想从中检索值,但它似乎没有在我的bean类中调用setter方法
这是我的bean类:

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "employees")
public class Employee implements Serializable{

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private int id;

    @Column(name = "first_name")
    private String firstName;

    @Column(name = "last_name")
    private String lastName;

    public Employee() {}

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

}
我试图在我的
ManagedBean
类中获取firstName字符串,但它返回
null

这是我的控制器类:

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.myapp.model.Employee;

@ManagedBean(name = "controller")
@SessionScoped
public class EmployeeController {

    private Employee employee;  

    @PostConstruct
    public void init()
    {
        employee = new Employee();
    }

    public Employee getEmployee()
    {
        return employee;
    }

    public void showInfo()
    {
        System.out.println("first name: " + employee.getFirstName());
    }

}
这是我的.xhtml文件

<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>  

    </h:head>  

    <h:body>  
        <h2>Input:</h2>
        <br/>
        <p:panelGrid columns="2">
            <p:outputLabel value = "First Name:" />
            <p:inputText value = "#{controller.employee.firstName}" />

        </p:panelGrid>
        <br/>
        <h:form>
            <p:commandButton value="Save Edits" action="#{controller.showInfo()}"> </p:commandButton>
        </h:form>
    </h:body>  
</html>  

输入:


我做错了什么?

组件必须是正在提交的
组件的一部分:

<h:form>
    <h2>Input:</h2>
    <br/>
    <p:panelGrid columns="2">
        <p:outputLabel value = "First Name:" />
        <p:inputText value = "#{controller.employee.firstName}" />
    </p:panelGrid>
    <br/>

    <p:commandButton value="Save Edits" action="#{controller.showInfo()}" /> 
</h:form>

输入:



我可以建议从一些基本的jsf教程开始吗?每个jsf教程都有关于这方面的例子。如果你不得不这样问这个问题,我会屏住呼吸,等待下一个问题变得更复杂(或者更简单一些)。值得注意的是,有人甚至对这个问题投了赞成票