我是JSF的新手。任何帮助,将不胜感激。 :)
.xhtml文件
<ui:composition template="templates/layoutTemplate.xhtml"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<ui:define name="script"> <h:outputScript library="javascript" name="resources/datetimepicker-master/jquery.datetimepicker.js" target="head"/> </ui:define>
<ui:define name="content">
<div class="col-sm-6" style="margin-left:25px;">
<div class="well bs-component">
<legend>New Patient</legend>
<h:form>
<div class="form-group">
<label for="inputPatientNumber" class="col-sm-3 control-label">Patient
Id </label>
<div class='col-sm-4' >
<h:inputText id="inputPatientNumber" styleClass="form-control"
p:placeholder="patient Id" value="#{addPatient.patientId}" >
<f:ajax event="blur" listener="#{addPatient.isExitsPatientId}" render="hiddenText" >
</f:ajax>
<f:ajax update="addPatientForm" />
</h:inputText>
</div>
<br/>
<h:inputHidden id="hiddenText" value="#{addPatient.isNewPatient}" ></h:inputHidden>
</div>
</h:form>
<br/>
<h:panelGroup id="addPatientForm" layout="block" style="display:#{addPatient.isNewPatient}" rendered="#{addPatient.newPatient }">
<div>
<h:form class="form-horizontal" >
<div class="form-group">
<label for="patientFirstName" class="col-sm-3 control-label">First Name</label>
<div class='col-sm-4'>
<h:inputText id="patientFirstName" styleClass="form-control"
p:placeholder="First Name" value="#{addPatient.firstName}" required="true" requiredMessage="First name required" validatorMessage="allowed alphabets only">
<f:validateRegex pattern="[a-zA-Z]+"/>
</h:inputText>
<h:message for="patientFirstName" style="color:red;margin:8px;" />
</div>
<label for="patientLastName" class="col-sm-2 control-label">Last Name</label>
<div class='col-sm-3'>
<h:inputText id="patientLastName" styleClass="form-control"
p:placeholder="Last Name" value="#{addPatient.lastName}" required="true" requiredMessage="Last name required" validatorMessage="allowed alphabets only">
<f:validateRegex pattern="[a-zA-Z]+"/>
</h:inputText>
<h:message for="patientLastName" style="color:red;margin:8px;" />
</div>
</div>
<div class="form-group">
<label for="dateOfBirth" class="col-sm-3 control-label">Date Of Birth </label>
<div class="col-sm-4">
<div class='input-group date'>
<h:inputText id="dateOfBirth" styleClass="form-control" value="#{addPatient.dob}" p:placeholder="13-12-1985" required="true" requiredMessage="Provide a valid date">
<f:convertDateTime pattern="dd-MM-yyyy" />
</h:inputText>
<h:message for="dateOfBirth" style="color:red;margin:8px;" />
</div>
</div>
<label for="gender" class="col-sm-2 control-label">Gender </label>
<div class="col-sm-3">
<h:selectOneMenu class="form-control" id="genderType" value="#{addPatient.gender}" required="true" requiredMessage="select gender">
<f:selectItem itemValue="#{null}" itemLabel="--Gender --" />
<f:selectItem itemValue="Male" itemLabel="Male"/>
<f:selectItem itemValue="Female" itemLabel="Female" />
</h:selectOneMenu>
<h:message for="genderType" style="color:red;margin:8px;" />
</div>
</div>
<div class="form-group">
<label for="inputFirstName" class="col-sm-3 control-label">Identification Type </label>
<div class="col-sm-4">
<h:selectOneMenu class="form-control" id="identificationType" value="#{addPatient.identificationType}" required="true" requiredMessage="Select the identification type">
<f:selectItem itemValue="#{null}" itemLabel="--Select ID Type --" />
<f:selectItem itemValue="Passport Number" />
<f:selectItem itemValue="Driving Licence" />
<f:selectItem itemValue="Social Security Code" />
<f:selectItem itemValue="Permanent Account Number" />
</h:selectOneMenu>
<h:message for="identificationType" style="color:red;margin:8px;" />
</div>
<label for="idType" class="col-sm-2 control-label">ID </label>
<div class="col-sm-3">
<h:inputText id="idType" value="#{addPatient.identificationNumber}" styleClass="form-control" p:placeholder="id" required="true" requiredMessage="Provide your id">
</h:inputText>
<h:message for="idType" style="color:red;margin:8px;" />
</div>
</div>
<div class="form-group">
<label for="address" class="col-sm-3 control-label">Address </label>
<div class="col-sm-4">
<h:inputText id="address" value="#{addPatient.address}" styleClass="form-control" p:placeholder="address" required="true" requiredMessage="Provide your address">
</h:inputText>
<h:message for="address" style="color:red;margin:8px;" />
</div>
<label for="line1" class="col-sm-2 control-label">Line 1 </label>
<div class='col-sm-3'>
<h:inputText id="line1" value="#{addPatient.addressLine1}" styleClass="form-control" p:placeholder="line 1" >
</h:inputText>
</div>
</div>
<div class="form-group">
<label for="line2" class="col-sm-3 control-label">Line 2 </label>
<div class="col-sm-4">
<h:inputText id="line2" value="#{addPatient.addressLine2}" styleClass="form-control" p:placeholder="line 2" >
</h:inputText>
</div>
<label for="city" class="col-sm-2 control-label">City </label>
<div class='col-sm-3'>
<h:inputText id="city" value="#{addPatient.addressCity}" styleClass="form-control" p:placeholder="city" >
</h:inputText>
</div>
</div>
<div class="form-group">
<label for="state" class="col-sm-3 control-label">State </label>
<div class="col-sm-4">
<h:inputText id="state" value="#{addPatient.addressState}" styleClass="form-control" p:placeholder="state" >
</h:inputText>
</div>
<label for="postalCode" class="col-sm-3 control-label">Postal Code </label>
<div class='col-sm-2'>
<h:inputText id="postalCode" value="#{addPatient.addressPostalCode}" styleClass="form-control" p:placeholder="Postal Code" >
</h:inputText>
</div>
</div>
<div class="form-group">
<label for="mobile" class="col-sm-3 control-label">Mobile </label>
<div class="col-sm-4">
<h:inputText id="mobile" value="#{addPatient.patientMobileNumber}" size="20" styleClass="form-control" p:placeholder="Mobile Number" required="true" requiredMessage="Mobile Number is required" validatorMessage="mobile number should start with + and can not be more than 15 digits.">
<f:validateRegex pattern="((^[/+][0-9]{0,12}$))" />
<f:validateLength minimum="12" maximum="15" />
</h:inputText>
<h:message for="mobile" style="color:red;margin:8px;" />
</div>
<label for="line1" class="col-sm-2 control-label">Language </label>
<div class='col-sm-3'>
<h:inputText id="language" value="#{addPatient.language}" styleClass="form-control" p:placeholder="language" >
</h:inputText>
</div>
</div>
<div class="form-group">
<div class="col-sm-3 col-sm-offset-3">
<div class="col-sm-3 ">
<h:commandButton class="btn btn-default" value="Clear" type="reset" />
<h:outputText value=" " />
</div>
<div class="col-sm-3 col-sm-offset-5 ">
<h:commandButton action="#{addPatient.nextClick}" value="Next" styleClass="btn btn-primary"/>
</div>
</div>
</div>
</h:form>
</div>
</h:panelGroup>
</div>
</div>
</ui:define>
</ui:composition>
BEAN
public String isExitsPatientId(AjaxBehaviorEvent e){
ExternalContext externalContext =
FacesContext.getCurrentInstance().getExternalContext();
String orgId = (String)externalContext.getSessionMap().get(JansmsDrapSolutionSqlQueryConstants.ALS_ORGID);
System.out.println(patientId +"org ="+ orgId);
sLogger.debug("Patient info being retrieved...");
ResultSet rSet;
String retrievePatientInfo = queryFile.getProperty(JansmsDrapSolutionSqlQueryConstants.SQL_QUERY_PATIENT_EXITS);
retrievePatientInfo = retrievePatientInfo.replaceAll("ALS_PATIENT_EXT_ID", patientId);
retrievePatientInfo = retrievePatientInfo.replaceAll("ORGID", orgId);
sLogger.debug(retrievePatientInfo);
try {
rSet = dbInteraction.executeQuery(retrievePatientInfo);
//patientMap = new LinkedHashMap<String,String>();
Integer counter = 0;
while(rSet.next()) {
counter++;
}
if(counter>0){
this.isNewPatient = "none";
newPatient = false;
sLogger.debug("patient already exits" + newPatient);
return this.isNewPatient;
}else{
this.isNewPatient = "true";
newPatient = true;
sLogger.debug("new patient" + newPatient);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
return "addPatient";
}
isExitsPatientId()方法为isNewPatient bean提供正确的布尔值,为true或none。但是,直到我按两次输入才会隐藏ui。通过删除对inputText的关注调用isExitsPatientId()方法并提供正确的数据,但隐藏panelGroup不起作用。