I am having a problem with an ajax behavior event not being fired immediately as text is typed in a field.
If the field is a String no problem, but I am using a Date.
xhtml:
<h:outputLabel value="Date of Birth:" />
<h:inputText id="searchDOB" value="#{search.dob}" required="true">
<f:ajax event="keyup" listener="#{search.addHyphensToDOB}" render=":output" />
<f:convertDateTime pattern="dd-MMM-yyyy" />
bean:
Date dob;
public void addHyphensToDOB(AjaxBehaviorEvent abe) {
System.out.println("addHyphen");
}
The event is only fired after typing the following:
22-JAN-
And fires on any number after the second hyphen, but not before.
One solution could be to change the Date type to a String, then format without using converter, but I would like to keep the Date type.
Any suggestions, thanks.
Eclipse 3.7, tomcat 7, jsf2.1,
It’s not fired because a conversion error has occurred due to invalid date format. The submitted value is converted everytime before the bean listener method is hit. Add a
<h:message>/<h:messages>and include its ID in<f:ajax render>. You’ll then see it.A
Stringvalue of for example2can impossibly represent a validDateobject when parsed with the patterndd-MMM-yyyy.You’ll really need to keep it a
Stringif you want to achieve the functional requirement this way. As a completely different alternative, you could consider to do it entirely at the JavaScript side without sending JSF ajax requests.