• Prajna
  • 0 Points
  • Member since 2012

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 1

Hi guys.


Bit of a conundrum here...


I've got a VF page that has an inputText field that users use to scan in barcodes using a handheld barcode scanner.

The barcode scanner merely act like a keyboard: it translates the scan to keys, then types those keys and hits enter.


What I'd like to do, is have users scan a barcode, then conduct an apex query. If the results are good, it updates a record, if the results are bad - it throws a pageMessage.


I got some JS that checks when the enter key is hit, and then I envoke the apex. However, there seems to be an issue with the sequence of reRendering and apex, and JS.


When I do the scan into the input field - the page does a refresh - but the apex:PageMessage that should display does not...


Here's what I have so far:



<apex:page standardController="terminalPrepOrder__c" extensions="terminalPrepOrderController" >
<apex:variable var="prp" value="{!terminalPrepOrder__c}"/>

function checkEnter(e){ <!-- e is event object passed from function invocation -->
var characterCode <!--literal character code will be stored in this variable -->

if(e && e.which){ <!--if which property of event object is supported (NN4) -->
e = e
characterCode = e.which <!-- character code is contained in NN4's which property -->
e = event
characterCode = e.keyCode <!-- character code is contained in IE's keyCode property -->

if(characterCode == 13){ <!-- if generated character code is equal to ascii 13 (if enter key) -->
alert("clicked enter");
otherFindTerminal(); <!-- submit the form -->
return false;
return true

<apex:pageMessages id="msgs"/>
<apex:form id="theForm"> <apex:actionFunction name="findTerminal" action="{!otherFindTerminal}" reRender="msgs"/> <apex:outputText value="Scan Terminal Barcode "/> <apex:inputText value="{!searchBarcode}" onkeypress="checkEnter(event)"/> <apex:commandButton value="Find" action="{!otherFindTerminal}" id="hitMe" reRender="msgs"/> </apex:form>



	public PageReference otherFindTerminal() {  
        try {
            if (searchBarcode != '') {
              terminal__c enteredTrm = [select Id from Terminal__c T where T.barcodeNumber__c = :searchBarcode limit 1];        
             terminalPrepOrder__c trmPrp = (terminalPrepOrder__c) controller.getRecord();
             trmPrp.Terminal__c = enteredTrm.Id;
             update trmPrp;
            else if (searchBarcode == '' ) {
                ApexPages.Message invalidSearch = new ApexPages.Message(ApexPages.Severity.ERROR, 'Invalid barcode.');
        catch (exception e) {
            ApexPages.Message noTrm = new ApexPages.Message(ApexPages.Severity.ERROR, searchBarcode + ' not found. Please enter the Terminal barcode.');
        return null;




So when I click the commandButton - it functions perfectly - It does the query, and rerenders the messages...


When I use the input field and hit enter... it refreshes the page but does nothing...



Please help!


  • May 10, 2010
  • Like
  • 0