I have two fields I want to fill using data scanned from a barcode however it seems like when I use two codescanners, the event gets called twice and both fields fill up with the same scanned data which is not what I want.
Here is my code:
</h:form>
<p:growl id="growl" showDetail="true" showSummary="true" globalOnly="false">
<p:autoUpdate/>
</p:growl>
<h:form id="form">
<div class="ui-fluid mb-4">
<div class="card border-none">
<p:tooltip/>
<h:form>
<p:messages id="messages" showDetail="true" closable="true" escape="false">
<p:autoUpdate/>
</p:messages>
</h:form>
</div>
<div class="card mb-4">
<p:dataTable id="dt-scannedPo" var="po" value="#{registerView.delivery.deliveryPurchaseOrders}">
<p:column headerText="PO Number">
<h:outputText value="#{po.purchaseOrder.poNumber}"/>
</p:column>
<p:column headerText="Invoice Number">
<h:outputText value="#{po.invoiceNumber}"/>
</p:column>
</p:dataTable>
<p:commandButton value="Submit Deliveries" oncomplete="PF('submitDeliveriesDialog').show()"
process="#this"/>
</div>
<p:confirmDialog widgetVar="submitDeliveriesDialog" showEffect="fade" width="300"
message="Submit #{registerView.delivery.deliveryPurchaseOrders.size()} deliveries?"
header="Confirm"
severity="warn">
<p:commandButton value="Yes" icon="pi pi-check" actionListener="#{registerView.addDeliveries}"
process="#this" oncomplete="PF('submitDeliveriesDialog').hide()"/>
<p:commandButton value="No" type="button" styleClass="ui-button-secondary" icon="pi pi-times"
onclick="PF('submitDeliveriesDialog').hide()"/>
</p:confirmDialog>
<div class="card border-none">
<div class="p-field p-grid">
<label for="name" class="p-col-12 p-2 p-md-2 p-mb-md-0 pl-0">Name</label>
<div class="p-col-12 p-md-10">
<p:inputText id="name" type="text" value="#{registerView.driverName}"/>
</div>
</div>
<div class="p-field p-grid">
<label for="contactNo" class="p-col-12 p-2 p-md-2 p-mb-md-0 pl-0">Contact Number (SG only)</label>
<div class="p-col-12 p-md-10">
<p:inputText id="contactNo" type="number" value="#{registerView.driverNumber}"
required="true" requiredMessage="Contact Number is required"/>
</div>
</div>
<div class="p-field p-grid">
<label for="vehicleNo" class="p-col-12 p-2 p-md-2 p-mb-md-0 pl-0">Vehicle Number</label>
<div class="p-col-12 p-md-10">
<p:inputText id="vehicleNo" type="text" value="#{registerView.driverLicensePlate}"
required="true" requiredMessage="License plate is required"/>
</div>
</div>
<div class="p-field p-grid">
<label for="poNumber" class="p-col-12 p-2 p-md-2 p-mb-md-0 pl-0">PO Number</label>
<div class="p-col-12 p-md-10">
<div class="ui-inputgroup">
<p:inputText id="poNumber" type="text" value="#{registerView.poNumber}" required="true"
requiredMessage="PO number is required"/>
<p:commandButton icon="fa fa-camera" styleClass="ui-button-success" pt:data-tooltip="Upload Image for OCR" action="#{ocr.detect()}"/>
<p:commandButton id="poBtn" icon="fa fa-qrcode" styleClass="ui-button-danger"
pt:data-tooltip="Scan QR Code/Barcode"
onclick="PF('poBarcodeDialog').show()"
immediate="true"/>
</div>
</div>
</div>
<div class="p-field p-grid mb-4">
<label for="invoiceNumber" class="p-col-12 p-2 p-md-2 p-mb-md-0 pl-0">Invoice Number</label>
<div class="p-col-12 p-md-10">
<div class="ui-inputgroup">
<p:inputText id="invoiceNumber" type="text" value="#{registerView.invoiceNumber}"/>
<p:commandButton icon="fa fa-camera" styleClass="ui-button-success" pt:data-tooltip="Upload Image for OCR" action="#{ocr.detect()}"/>
<p:commandButton id="invBtn" icon="fa fa-qrcode" styleClass="ui-button-danger"
pt:data-tooltip="Scan QR Code/Barcode"
onclick="PF('invBarcodeDialog').show()"
immediate="true"/>
</div>
</div>
</div>
<p:commandButton update="#form" value="Add to delivery list"
action="#{registerView.addPurchaseOrderToDelivery}"/>
</div>
</div>
</h:form>
<!--Barcode Dialog for PO-->
<p:dialog header="Scan Barcode/QR Code" widgetVar="poBarcodeDialog" showEffect="fade" modal="true">
<div class="p-grid">
<pe:codeScanner for="form:poNumber" id="poScanner">
<p:ajax event="codeScanned" listener="#{registerView.onPOCodeScanned}"/>
</pe:codeScanner>
</div>
</p:dialog>
<!--Barcode Dialog for Invoice-->
<p:dialog header="Scan Barcode/QR Code" widgetVar="invBarcodeDialog" showEffect="fade" modal="true">
<div class="p-grid">
<pe:codeScanner for="form:invoiceNumber" id="invScanner">
<p:ajax event="codeScanned" listener="#{registerView.onInvCodeScanned}"/>
</pe:codeScanner>
</div>
</p:dialog>
public void onPOCodeScanned(final SelectEvent<Code> event) {
final Code code = event.getObject();
logger.info("Code scanned: " + code.getValue());
logger.info("Prev Code scanned: " + poNumber);
poNumber = code.getValue();
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Code scanned: ", code.getValue()));
PrimeFaces.current().ajax().update("form:growl");
}
public void onInvCodeScanned(final SelectEvent<Code> event) {
final Code code = event.getObject();
logger.info("Code scanned: " + code.getValue());
logger.info("Prev Code scanned: " + invoiceNumber);
invoiceNumber = code.getValue();
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Code scanned: ", code.getValue()));
PrimeFaces.current().ajax().update("form:growl");
}
If anyone has any idea on how to fix this please let me know thanks in advance.
I don't think your approach with multiple instances is going to work. At least not when you use the same video device on both instances. Different devices might work, but is awkward in my opinion. Since you are now using the same video device on both instances, it is expected that listeners are being called twice.
What you should do is use a single dialog (so a single scanner) and set a property. This way your dialog and scanner will know for which input it should scan, and you should use that in your listener.
Related
I have h:form in PrimeFaces p:dialog. All other components works fine, even the p:selectOneMenu, but value of p:inputText is not bound to bean and gives null.
<p:dialog header="Delivery Schedule" id="deleditdlg" widgetVar="deleddlg1" showEffect="clip"
hideEffect="clip" styleClass="dialogwidth"
modal="true" appendTo="#(body)" closable="true" width="500">
<h:form id="saveform">
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<h:outputLabel style="font-weight: bold;"
value="Timing: "></h:outputLabel>
<br/>
<p:inputText value="#{deliveryScheduleBean.deliverySchedule.vehTiming}"></p:inputText>
</div>
<div class="col-md-3">
<h:outputLabel style="font-weight: bold;"
value="Status: "></h:outputLabel>
<br/>
<p:selectOneMenu value="#{deliveryScheduleBean.deliverySchedule.vehStatus}">
<f:selectItem itemLabel="Active" itemValue="0"></f:selectItem>
<f:selectItem itemLabel="Inactive" itemValue="1"></f:selectItem>
</p:selectOneMenu>
</div>
</div>
<br />
<div class="row">
<div class="col-md-4 ml-auto">
<p:commandButton class="btn btn-success" process="saveform"
action="#{deliveryScheduleBean.updateSchedule}" value="Save"></p:commandButton>
</div>
</div>
</div>
</h:form>
</p:dialog>
This is my Table
Lets say i have 10 user in the table and i click user id 2 to edit, the bootsfaces modal display the last user in the table into modal; which is user id 10.
<div class="tab-pane fade" id="add9">
<h:form class="form-horizontal" >
<h3 class="title-section title-bar-high mb-40">System User Report</h3>
<div class="orders-info">
<div class="table-responsive">
<b:dataTable class="table table-bordered table-responsive" var="user" value="#{userBean.findsAll()}" onorder="console.log('order');" onselect="ajax:userBean.editUser(user)" onpage="console.log('page');" >
<h:column>
<f:facet name="header">Sr. No.</f:facet>
<h:outputText value="#{user.id}" />
</h:column>
<h:column>
<f:facet name="header">Name</f:facet>
<h:outputText value="#{user.userName}" />
</h:column>
<h:column>
<f:facet name="header">Status</f:facet>
<h:outputText value="#{user.userLevel}" />
</h:column>
<h:column>
<f:facet name="header">Mobile</f:facet>
<h:outputText value="#{user.userPhone}" />
</h:column>
<h:column>
<f:facet name="header">Email</f:facet>
<h:outputText value="#{user.userEmail}" />
</h:column>
<h:column>
<f:facet name="header">Date</f:facet>
<h:outputText value="#{user.userDate}" />
</h:column>
<h:column>
<f:facet name="header">Action</f:facet>
<b:commandButton iconAwesome="pencil" look="link" action="#{userBean.editUser(user)}" onclick="$('.modalPseudoClass').modal();return false;">
<f:ajax execute="#{userBean.editUser(user)}" render="#none" />
</b:commandButton>
<b:commandButton action="#{userBean.deleteUser(user)}" onclick="return confirm('You Are About You Delete This User!')" iconAwesome="trash" look="link">
</b:commandButton>
</h:column>
</b:dataTable>
</div>
</div>
</h:form>
</div>
This is my beans controller
public class UserBean implements Serializable {
#EJB
private UserFacade userFacade;
private User user;
public UserBean() {
user = new User();
}
public UserFacade getUserFacade() {
return userFacade;
}
public void setUserFacade(UserFacade userFacade) {
this.userFacade = userFacade;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public void deleteUser(User user){
userFacade.remove(user);
}
public void editUser(User user){
this.user = user;
}
public void editUser(){
userFacade.edit(this.getUser());
user = new User();
}
}
This is my bootsfaces modal
<f:view>
<h:form class="form-horizontal">
<b:modal id="amodal" title="Basic info and Contact No. #{userBean.user.id}" styleClass="modalPseudoClass">
<div class="profile-details tab-content">
<div class="personal-info">
<div class="form-group">
<h:outputLabel class="col-sm-3 control-label" for="userName">User Name:</h:outputLabel>
<div class="col-sm-9">
<h:inputText class="form-control" id="userName" value="#{userBean.user.userName}" title="UserName" requiredMessage="" />
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<h:outputLabel class="col-sm-3 control-label" for="firstName">First Name:</h:outputLabel>
<div class="col-sm-9">
<h:inputText class="form-control" id="firstName" value="#{userBean.user.firstName}" title="FirstName" requiredMessage="" />
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<h:outputLabel class="col-sm-3 control-label" for="lastName">last-name:</h:outputLabel>
<div class="col-sm-9">
<h:inputText class="form-control" id="lastName" value="#{userBean.user.lastName}" title="LastName" requiredMessage="" />
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<h:outputLabel class="col-sm-3 control-label" for="userEmail">E-mail Address:</h:outputLabel>
<div class="col-sm-9">
<h:inputText class="form-control" id="userEmail" value="#{userBean.user.userEmail}" title="UserEmail" requiredMessage="" />
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<h:outputLabel class="col-sm-3 control-label" for="userPostal">Zip Code:</h:outputLabel>
<div class="col-sm-9">
<h:inputText class="form-control" id="userPostal" value="#{userBean.user.userPostal}" title="UserPostal" requiredMessage="" />
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<h:outputLabel class="col-sm-3 control-label" for="userPhone">Phone:</h:outputLabel>
<div class="col-sm-9">
<h:inputText class="form-control" id="userPhone" value="#{userBean.user.userPhone}" title="UserPhone" requiredMessage="" />
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<h:outputLabel class="col-sm-3 control-label" for="userCountry">Country:</h:outputLabel>
<div class="col-sm-9">
<div class="custom-select">
<h:selectOneMenu id="userCountry" value="#{userBean.user.userCountry}" title="UserCountry" class="select2">
<f:selectItem itemValue = "o" itemLabel = "Please Select" />
<f:selectItem itemValue = "Bangladesh" itemLabel = "Bangladesh" />
<f:selectItem itemValue = "Spain" itemLabel = "Spain" />
<f:selectItem itemValue = "Belgium" itemLabel = "Belgium" />
<f:selectItem itemValue = "Ecuador" itemLabel = "Ecuador" />
<f:selectItem itemValue = "Ghana" itemLabel = "Ghana" />
<f:selectItem itemValue = "South Africa" itemLabel = "South Africa" />
<f:selectItem itemValue = "India" itemLabel = "India" />
<f:selectItem itemValue = "Pakistan" itemLabel = "Pakistan" />
<f:selectItem itemValue = "Thailand" itemLabel = "Thailand" />
<f:selectItem itemValue = "Malaysia" itemLabel = "Malaysia" />
<f:selectItem itemValue = "Italy" itemLabel = "Italy" />
<f:selectItem itemValue = "Japan" itemLabel = "Japan" />
</h:selectOneMenu>
</div>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<h:outputLabel class="col-sm-3 control-label" for="userLevel">User Level:</h:outputLabel>
<div class="col-sm-9">
<div class="custom-select">
<h:selectOneMenu class="select2" id="userLevel" value="#{userBean.user.userLevel}" title="UserLevel">
<f:selectItem itemLabel="Choose item" noSelectionOption="true" />
<f:selectItems value="#{userBean.findAllUserRole()}" var="user" itemLabel="#{user.name}" itemValue="#{user.name}" />
<f:ajax render="#{user.name}" />
</h:selectOneMenu>
</div>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<h:outputLabel class="col-sm-3 control-label" value="Town / City:" for="userTown" />
<div class="col-sm-9">
<h:inputText class="form-control" id="userTown" value="#{userBean.user.userTown}" title="UserTown" requiredMessage="" />
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<h:outputLabel class="col-sm-3 control-label" for="userAbout">About Me:</h:outputLabel>
<div class="col-sm-9">
<h:inputTextarea class="form-control" id="userAbout" value="#{userBean.user.userAbout}" title="UserAbout" requiredMessage="" style="height: 150px;" rows="8" />
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<f:facet name="footer">
<div class="form-group mb-none">
<div class="col-sm-3">
<b:commandButton value="Save" look="success" style="width:80px" action="#{userBean.editUser()}" a:dismiss="modal" />
</div>
<div class="col-sm-3">
<b:button value="Close" look="warning" style="width:80px" dismiss="modal" />
</div>
</div>
</f:facet>
</div>
</b:modal>
</h:form>
</f:view>
You need to update the content of the modal when the user selects a row. You know, the datatable and the modal are part of the same XHTML file, so they are rendered at the same time. Of course, that's too early, so the modal shows the wrong user if it isn't updated.
BTW, I believe it's a good idea to rename user to selectedUser, initialize it with null, and to render the content of the modal only if the selectedUser is not null. That way, you notice when something's wrong. Plus, less HTML code is sent to the client.
Not directly related to your question: your code snippet calls editUser() multiple times. You may want to do some housekeeping.
I am new to JSF. Any help would be appreciated. :)
.xhtml file
<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";
}
The isExitsPatientId() method is providing correct boolean value and either true or none for isNewPatient bean. However, the ui is not hidden until i press enter twice. by removing the focus on inputText calls the isExitsPatientId() method and provides the correct data but hiding the panelGroup is not working.
I want to reset values when I submit a form.
<h:form id="form">
<div class="success_wrapper">
<div class="success-message">Contact form submitted</div>
</div>
<div class="string">
<label class="name">
<h:inputText id="name" value="#{mailhandler.name}" pt:placeholder="Name*:"/>
</label>
<label class="email">
<h:inputText id="email" value="#{mailhandler.senderEmail}" pt:placeholder="E-mail*:"/>
</label>
<label class="phone">
<h:inputText id="telephone" value="#{mailhandler.telephone}" pt:placeholder="Telephone*:"/>
</label>
</div>
<label class="message">
<h:inputTextarea value="#{mailhandler.comment}" pt:placeholder="Comment*:"/>
</label>
<div class="clear"></div>
<div class="btns">
<h:commandLink id="submitlink" class="link" value="submit" action="#{mailhandler.sendEmail}" >
<f:ajax render="#form" execute="#form" onevent="handleDisableButton" resetValues="true"/>
</h:commandLink>
</div>
<br/>
<h:outputText id="output" value="#{mailhandler.result}" />
</h:form>
I tested this code example but for some reason the old values are still kept after the AJAX call.
I added resetValues="true" but the result is the same. Can you help me to find the issue?
I want to use a ui:repeat or any other iterative tag to display a number of components once
for each item in an Array list.
<!-- print multiple mandates -->
<ui:repeat id="mandates" var="mandate" value="#{taxheadDirectDebit.mandates}">
<a4j:region id="remittanceDetailsSection"
rendered="#{(taxheadDirectDebit.accountFinancialInfo.registration.type != 'PREM') or (taxheadDirectDebit.accountFinancialInfo.registration.type != 'VAT')}">
<!-- Remittance Details -->
<fieldset><legend class="sub"> <h:outputText
value="#{msg['remittanceDetails.title']}" /> </legend>
<!-- Estimated Liability -->
<div class="field">
<div class="label"><label for="allocatedAmount"><h:outputText
for="estimatedLiability"
value="#{msg['remittanceDetails.estimatedLiability']}" /> </label><span
class="requiredFlag">*</span></div>
<div class="error">
<rich:message styleClass="errorText" for="estimatedLiability" />
</div>
<div class="input">
<h:inputText id="estimatedLiability" size="30"
maxlength="11" label="#{msg['registerContractPage1.subTaxNumber']}"
value="#{taxheadDirectDebit.estimatedLiability}">
<a4j:ajax event="change" render="remittanceFrequency" />
</h:inputText>
</div>
<br class="clear" />
</div>
<!-- Is Seasonal -->
<div class="field">
<div class="label"><label for="isSeasonal"> <h:outputText
for="isSeasonal"
value="#{msg['remittanceDetails.isTheNatureSeasonal']}" /> </label><span
class="requiredFlag">*</span></div>
<div class="error"><rich:message styleClass="errorText"
for="isSeasonal" /></div>
<div class="input"><h:selectOneRadio id="isSeasonal"
label="#{msg['remittanceDetails.isTheNatureSeasonal']}"
value="#{taxheadDirectDebit.isSeasonal}"
styleClass="radioLabelTop">
<ddo:twoOptionSelection />
<a4j:ajax event="click" render="remittanceFrequency" />
</h:selectOneRadio></div>
<br class="clear" />
</div>
</fieldset>
</a4j:region>
<!-- Remittance Frequency -->
<a4j:outputPanel id="remittanceFrequency">
<div class="field">
<div class="label"><label for="allocatedAmount"><h:outputText
for="estimatedLiability"
value="#{msg['remittanceDetails.estimatedLiability']}" /> </label><span
class="requiredFlag">*</span></div>
<div class="error">
<rich:message styleClass="errorText" for="estimatedLiability" />
</div>
<div class="input">
<h:inputText id="estimatedLiability" size="30"
maxlength="11" label="#{msg['registerContractPage1.subTaxNumber']}"
value="#{taxheadDirectDebit.estimatedLiability}">
<a4j:ajax event="change" render=":remittanceDetails:mandates:remittanceFrequency" />
</h:inputText>
</div>
<br class="clear" />
</div>
<fieldset><legend class="sub"> <h:outputText
value="#{msg['remittanceDetails.frequency']}" /> </legend>
<!-- Amount to be Debited -->
<div class="field">
<div class="label"><label for="amountEachMonth"><h:outputText
for="amountEachMonth"
value="#{msg['remittanceDetails.amountToBeDebited']}" /> </label></div>
<div class="error"><rich:message styleClass="errorText"
for="amountEachMonth" /></div>
<div class="input"><h:inputText id="amountEachMonth" size="30" readOnly="true"
maxlength="8" label="#{msg['remittanceDetails.amountToBeDebited']}"
value="#{mandate.remittanceDetails.amountEachMonth}">
<a4j:ajax event="change" render="remittanceFrequencyNoDebitedEachMonth"/>
</h:inputText></div>
<br class="clear" />
</div>
<a4j:outputPanel id="remittanceFrequencyNoDebitedEachMonth">
<!-- Months -->
<div class="field">
<div class="grid1"><h:outputText
value=" " />
</div>
<rich:panel styleClass="ddo-panel" rendered="#{taxheadDirectDebit.isSeasonal == 1}">
<div class="grid2"><div align="center">
<h:outputText value="#{msg['reviewDetails.reduce']}"/><div align="center"></div>
</div></div>
</rich:panel>
<rich:panel styleClass="ddo-panel" rendered="#{taxheadDirectDebit.action == 'AMEND'}">
<div class="grid3">
<div align="center">
<h:outputText value="#{msg['reviewDetails.suspend']}"/><div align="center"></div>
</div>
</div>
</rich:panel>
<rich:panel styleClass="ddo-panel" rendered="#{taxheadDirectDebit.isSeasonal == 1}">
<div class="grid2">
<div align="center">
<h:outputText value="#{msg['reviewDetails.exclude']}"/><div align="center"></div>
</div>
</div>
</rich:panel>
<br class="clear" />
<div class="floatleft">
<div class="row3">
<div class="row1">
<!-- January -->
<!-- Months Column -->
<div class="grid1">
<label>
<h:outputText readOnly="true" disabled="true" size="4" value="#{msg['calendar.month.0']}" />
</label>
</div>
<!-- Reduce check box -->
<rich:panel styleClass="ddo-panel" rendered="#{taxheadDirectDebit.isSeasonal == 1}">
<div class="grid2">
<div align="center">
<h:selectBooleanCheckbox
id="reduce12"
value="#{mandate.remittanceDetails.remittanceFrequencys[0].reduce}"
disabled="#{mandate.remittanceDetails.remittanceFrequencys[0].exclude}">
<a4j:ajax event="click" render="remittanceFrequency" />
</h:selectBooleanCheckbox>
</div>
</div>
</rich:panel>
<!-- Suspend check box -->
<rich:panel styleClass="ddo-panel" rendered="#{taxheadDirectDebit.isSeasonal != 1}">
<div class="grid2hidden">
<h:outputText value=" " />
</div>
</rich:panel>
<rich:panel styleClass="ddo-panel" rendered="#{taxheadDirectDebit.action == 'AMEND'}">
<div class="grid3">
<div align="center">
<h:selectBooleanCheckbox
id="suspend0"
value="#{mandate.remittanceDetails.remittanceFrequencys[0].suspend}">
<a4j:ajax event="change" />
</h:selectBooleanCheckbox>
</div>
</div>
</rich:panel>
<!-- Exclude check box -->
<rich:panel styleClass="ddo-panel" rendered="#{taxheadDirectDebit.isSeasonal == 1}">
<div class="grid2">
<div align="center">
<h:selectBooleanCheckbox
id="exclude0"
value="#{mandate.remittanceDetails.remittanceFrequencys[0].exclude}"
disabled="#{mandate.remittanceDetails.remittanceFrequencys[0].reduce}">
<a4j:ajax event="change" render="remittanceFrequency" />
</h:selectBooleanCheckbox>
</div>
</div>
</rich:panel>
<rich:panel styleClass="ddo-panel" rendered="#{taxheadDirectDebit.isSeasonal != 1}">
<div class="grid2hidden">
<h:outputText value=" " />
</div>
</rich:panel>
<div class="errorRemittance">
<rich:message styleClass="errorText" for="remittanceAmount0"/>
</div>
<!-- Monthly Amount field -->
<div class="grid5">
<h:inputText
id="remittanceAmount0" size="30" maxlength="8" readOnly="true"
value="#{mandate.remittanceDetails.remittanceFrequencys[0].amount}"
disabled="#{!mandate.remittanceDetails.remittanceFrequencys[0].reduce}"
label="#{msg['remittanceDetails.amountToBeDebited']}">
<a4j:ajax event="change" render="remittanceFrequency" />
</h:inputText>
</div>
</div>
</div>
<div class="errorText" font="bold">
<rich:message styleClass="errorTextNoPadding" for="continue"/>
</div>
</div>
</div>
</a4j:outputPanel>
</fieldset>
</a4j:outputPanel>
<rich:message>
<rich:message for="remittanceFrequency" ajaxRendered="true" />
</rich:message>
</ui:repeat>
I've taken out a lot of my code here so there may be un macthed divs etc but the idea is there.
I have two problems:
You can see that some components have change events that render other components based on id. These don't work inside the repeat
I'm using webflow and adding messages to the message context so that the message tags can display validation messages but these don't work in the iteration either.
I have tried tr:iterator, c:forEach, a4j:repeat, tr:forEach. I'm pretty sure what I'm trying to do isn't possible the way I'm trying to do it so if anyone has experience trying to achieve similar I'd appreciate some help. I can't change the MVC frameowork I'm using but could use perhaps jQuery.
I solved this by moving the ajax region outside the repeat and just calling render on the whole region. Not beautiful I know but the quickest solution I could find.
On the message front I simply add the index of the item in the list being iterated over into the message.
"remittanceDetails:mandates:"+taxhead.getMandates().indexOF(mandate)+":remittanceAmount" + frequency.getMonth().getCode()
JSF looks after the rest.