1

I have simple add page to add a new record into the database. the page code is below,

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

managed bean classes

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();
}

}

three input box and 1 command button. the problem is when the first time I put the value and click "Submit" button, nothing happens. But it does success when I fill the value and click the button at second time.

  • If this is really the complete scenario, there should not be any problem. If it's more complex than that and maybe include several forms, you might check out https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-790 and try to include the javascript-workaround in your page. This bug makes it necessary to click a button twice in certain scenarios, but can be fixed with the workaround in the bugreport. – noone Aug 27 '13 at 06:02
  • Try adding `type="submit"` attribute to your `h:commandButton`. – Aritz Aug 27 '13 at 11:17
  • Please exclude cause #7 from http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked/2120183#2120183 – BalusC Aug 27 '13 at 11:26

0 Answers0