JavaScript / jQuery runs in the browser and runs on the HTML DOM tree, which is generated by JSF and sent to the browser, it does not intercept the JSF component tree. Your $("#date") will not return anything since there is no element with this identifier in the HTML DOM tree. Open the page in your browser, right-click and select "View Source". You will see that it was actually generated as <input id="form:date"> , and not as <input id="date"> .
Instead, you should use the following selectors (note that : is an illegal character in CSS and therefore must be escaped):
$("#form\\:date").mask("99/99/9999"); $("#form\\:phone").mask("(999) 999-9999"); $("#form\\:tin").mask("99-9999999"); $("#form\\:ssn").mask("999-99-9999");
or, without the need for an explicit exit:
$("[id='form:date']").mask("99/99/9999"); $("[id='form:phone']").mask("(999) 999-9999"); $("[id='form:tin']").mask("99-9999999"); $("[id='form:ssn']").mask("999-99-9999");
Or, otherwise, just give them a class name:
<h:inputText id="date" styleClass="date" /> <h:inputText id="phone" styleClass="phone" /> <h:inputText id="tin" styleClass="tin" /> <h:inputText id="ssn" styleClass="ssn" />
which is then more widely selected as follows, without the need to insert identifiers of possibly several input fields of the same type in the view, for example inside <h:dataTable> :
$("input.date").mask("99/99/9999"); $("input.phone").mask("(999) 999-9999"); $("input.tin").mask("99-9999999"); $("input.ssn").mask("999-99-9999");
Balusc
source share