3
I have a JSF form in which I add fields <input>
dynamically with AJAX.
When I click on <h:commandButton>
that trigger the routine of adding the <input>
the field is added however the mask I set for it is not applied. And in case I have already typed some value in the previous field, the memso disappears.
I wonder how to render the mask for each field that dynamically added without prejudice to data from other fields.
XHTML:
<h:panelGrid id="grid-phone" columns="1" class="accord-son-3">
<h:dataTable id="table-phone" value="#{cadastroUsuarioBean.items}" var="item" width="595">
<h:column><h:outputLabel value="Telefone" /></h:column>
<h:column ><h:inputText value="#{item.value}" class="column-cad phone" styleClass="phone"/></h:column>
<h:column>
<h:commandLink value="Remover" action="#{cadastroUsuarioBean.remove(item)}" class="jump-link" style="margin-left: 65px;"/>
</h:column>
</h:dataTable>
<h:commandButton type="button" value="Adicionar Telefone" class="btn" style="font:normal bold 12px Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin-top: 5px" >
<f:ajax listener="#{cadastroUsuarioBean.add}" render="table-phone" execute="@form"/>
</h:commandButton>
</h:panelGrid>
Java
public void add(AjaxBehaviorEvent event) {
items.add(new Item());
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
HttpSession session = (HttpSession) externalContext.getSession(true);
session.setAttribute("formulario", marca);
session.setAttribute("itens", items);
}
Javascript
<script>
jQuery(function($){
$("#form\\:date").mask("99/99/9999");
$("input.phone").mask("(99) 9999-9999");
$("#form\\:cep").mask("99999-999");
});
</script>