7 Replies Latest reply on Oct 22, 2011 3:07 PM by Raimund Hölle

    a4j:queue size never exceeds 2...

    Joachim Skeie Newbie

      Hello,

       

      I am attempting to develop a prototype for a handheld application where the user is using a barcode scanner. There are two modes, one for normal scanning with full feedback, and one for quick scanning of items for ordering. Using the 'fast mode' the user is expecting to be able to scan multiple barcodes. The application will queue up these scans and process them in the background (the user is faster than the server in this case).

       

      I have the following code (snipped for clarity):

       

      <a4j:region>
           <a4j:queue name="testqueue" requestDelay="0" size="50"
                  onsizeexceeded="alert('SIZE EXCEEDED');"
                  onsubmit="updateQueueSize();"
                  oncomplete="updateQueueSize();"
                  ignoreDupResponses="false"
                  onerror="alert('ERROR');"

                  onrequestqueue="updateQueueSize();"
                  onrequestdequeue="updateQueueSize();"/>

       

      ...

       

      <a4j:commandButton id="addButton" name="addButton" value="Add to Order" eventsQueue="testqueue"
           actionListener="#{mbean.save}" reRender="test1,queueText" disabled="#{!mbean.orderSelected}">
      </a4j:commandButton>

       

      <h:outputText id="test1" value="#{manuell.brukerMelding}"></h:outputText>
      <h:outputText id="queueText" value="TEST"></h:outputText>

       

      ...

       

      <script>
          function updateQueueSize() {
              document.getElementById('mainForm:queueText').innerHTML = 'Queue Size: ' + getQueueSize() + ' Max: ' + getMaxQueueSize();
          }

          function getQueueSize() {
              if (A4J.AJAX) {
                  with (A4J.AJAX) {
                      if (EventQueue.getQueue('mainForm:testqueue')) {
                          return EventQueue.getQueue('mainForm:testqueue').getSize();
                      }
                  }
              }

              return -1;
          }

          function getMaxQueueSize() {
              if (A4J.AJAX) {
                  with (A4J.AJAX) {
                      if (EventQueue.getQueue('mainForm:testqueue')) {
                          return EventQueue.getQueue('mainForm:testqueue').getMaximumSize();
                      }
                  }
              }

              return -1;
          }

      </script>

       

      Now. If I click the Add Button, the queue size becomes 1. Another click increments the queue size to 2. However subsequent clicks wont increase the queue size above 2. When one message is popped from the queue, though, I am able to increase the size to 2 again.

       

      I know that the RichFaces Framework attempt to group request coming from the same client, but in this case, I want to add the message to the queue regardless. I want to keep all the logic regarding the number of items ordered on the server side (two scans for the same bar code, means an order of 2 items, etc.).

       

      Is there something I am missing to be able to acheive this sort of functionality using a4j:queue ?