JSF 2.0 inputText不会在第一次更新bean属性,但会在第二轮更新

时间:2013-08-27 03:28:11

标签: database jsf

我有一个简单的添加页面,可以在数据库中添加新记录。页面代码如下,

    <h:form id="add_form">
    <h:inputText id="patientId" value="#{patientBean.patientId}" label="ID" required="true"/>
<h:inputText id="patientName" value="#{patientBean.patientName}" label="Name" required="true"/>
<h:inputText id="patientDesease" value="#{patientBean.patientDesease}" label="Desease" required="true"/>
<h:commandButton value="Submit" action="#{patientBean.addPatient()}" />
</h:form>

faces-config.xml中

    <managed-bean>
    <managed-bean-name>patientBean</managed-bean-name>
    <managed-bean-class>com.sunnus.pims.managedbean.PatientBean</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
        <property-name>patientsBo</property-name>
        <value>#{patientsBo}</value>
    </managed-property>
</managed-bean>

托管bean类

public class PatientBean implements Serializable{

/**
 * 
 */

PatientsBo patientsBo;
List<Patient> patients;
List<Patient> filteredPatients;

public List<Patient> getFilteredPatients() {
    return filteredPatients;
}

public void setFilteredPatients(List<Patient> filteredPatients) {
    this.filteredPatients = filteredPatients;
}

private String patientId;
private String patientName;
private String patientDesease;

public String addPatient() {
    Patient patient = new Patient();
    patient.setPatientName(getPatientName());
    patient.setPatientId(getPatientId());
    patient.setPatientDesease(getPatientDesease());
    patientsBo.addPatient(patient);
    clearPatientBean();
    return "";
}

private void clearPatientBean() {
    setPatientDesease("");
    setPatientId("");
    setPatientName("");
}

public PatientBean() {
}

public void setPatientsBo(PatientsBo patientsBo) {
    this.patientsBo = patientsBo;
    patients = patientsBo.findAllPatient();
}

public String getPatientId() {
    return patientId;
}

public void setPatientId(String patientId) {
    this.patientId = patientId;
}

public String getPatientName() {
    return patientName;
}

public void setPatientName(String patientName) {
    this.patientName = patientName;
}

public String getPatientDesease() {
    return patientDesease;
}

public void setPatientDesease(String patientDesease) {
    this.patientDesease = patientDesease;
}

public List<Patient> getAllPatientList() {
    return patientsBo.findAllPatient();
}

}

三个输入框和一个命令按钮。问题是当我第一次输入值并单击“提交”按钮时,没有任何反应。但是当我填充值并在第二次单击按钮时它会成功。

0 个答案:

没有答案