<h:inputText id="quantity"
value="#{_cartItem.quantity}" required="true" size="3"
maxlength="3">
<f:converter converterId="ValueConverter" />
<f:validateLongRange minimum="0" maximum="999" />
<a:support event="onchange"
ajaxSingle="true"
action="#{cSession.userCheckQuantity(_cartItem, index)}"
reRender="minicartAjax, shoppingCartAjax, orderTotalAjax"></a:support>
When you click off the Quantity input box the userCheckQuantity method is easily fired. But If I put in a number and quickly slam down the enter key on the keyboard the validation is missed.
How can I get the Enter key approach to validate as well? Let me know if I need to provide more code.
You’re doing the validation by Ajax exclusively. This is not robust enough. You need to replace the
action="#{cSession.userCheckQuantity(_cartItem, index)}"by a fullworthyValidatorimplementation which you bind to the input component as a<f:validator>. This way the validation will always take place, regardless of whether it’s been triggered by a change or a form submit.Inside the
Validatorimplementation, you could obtain the_cartItemandindexfrom theFacesContext. How exactly depends on where they are stored and what JSF spec version you’re using. If they’re for example stored as request attributes, you could useExternalContext#getRequestMap()to get them.