-
1. Re: force a4j:support onchange for field value from browser
nbelaevski Nov 19, 2008 7:42 PM (in response to francof)Franco,
Try onkeyup. Use eventsQueue/requestDelay attributes to protect server from flooding with requests: http://www.jboss.org/file-access/default/members/jbossrichfaces/freezone/docs/devguide/en/html/ArchitectureOverview.html#QueueandTrafficFloodProtection -
2. Re: force a4j:support onchange for field value from browser
francof Nov 19, 2008 11:21 PM (in response to francof)Thank you, I appreciate your guidance.
I added autocomplete="off" to my input text to prevent use of history.
I then tried your suggestion and wrote<a4j:support event="onkeyup" reRender="taxCodeDecoration" ajaxSingle="true" eventsQueue="taxEvents" requestDelay="5000" action="#{taxHome.validateTaxCode}"/>
It worked like a charm!
My only issue is this - since I have set a 5 second requestDelay,
what if the user starts typing in 1 character and then say starts talking to a colleague, after 5 secs, the query will fire automatically even b4 an actual onchange (user tabbed out) ? - of course I can increase the requestDelay. I guess my concern is will I pass UAT?
Thanks again, I can go to bed now :) -
3. Re: force a4j:support onchange for field value from browser
ilya_shaikovsky Nov 20, 2008 5:09 AM (in response to francof)using onkeyup - the request will be fired after request delay even if the filed was leaved.
using onblur instead of onkeyup you could fire the request only after the user stoped typing and leaved input. -
4. Re: force a4j:support onchange for field value from browser
francof Nov 20, 2008 7:05 AM (in response to francof)Thanks again.
I do have an onblur event that checks all the other validations (Hibernate validators) on my field in the model. I only have a custom @Required right now for this field.
Do you advise that I put my action method taxHome.validateTaxCode on the onblur event and let the method check for required value first ?
What if the field has other validations I want to check for like say @Length , if I put all these in my action method, guess I am breaking DRY principle, right?
Basically, I am trying to achieve this -
- trap all Hibernate validators on model then
- trap duplicate value entered.
Using onblur and then onkeyup events with the help from nbelaevski
helped, but is that the standard way for key field validations using ajax4jsf ?
Thanks and regards
Franco -
5. Re: force a4j:support onchange for field value from browser
francof Nov 20, 2008 4:28 PM (in response to francof)I think I can live with onkeyup.
Using onchange is so inconsistent in Firefox and IE -
In Firefox, the JSF error message from my action method would not appear always if the value was duplicate.
I wrote<h:inputText id="taxCode" required="true" label="Tax code" size="10" disabled="#{taxHome.managed}" autocomplete="off" maxlength="10" styleClass="#{invalid?'errors':''}" valueChangeListener="#{taxHome.recordTaxCodeChange}" value="#{taxHome.instance.taxCode}" > <a4j:support event="onblur" reRender="taxCodeDecoration" ajaxSingle="true" bypassUpdates="true" /> <a4j:support event="onkeyup" reRender="taxCodeDecoration" ajaxSingle="true" eventsQueue="taxEvents" requestDelay="4000" ignoreDupResponces="true" action="#{taxHome.validateTaxCode}"/> </h:inputText>
I added a valuechangedListener and save the current value into a variable on action class and use that to check for uniqueness.
This works consistently in both browsers now.
Thanks for your help guys.
If there is anyone else who has a different solution, I would love to hear.
Regards
Franco