Hello! I'm having difficulty doing a validation. It is the following ... I have a form made inside the components Primefaces 4.0 that has the fields "Cellular" and "Telephone". My intention is for the form to start with these two enabled fields, but when the mouse cursor focuses on one of them, the other is disabled, causing only "Cell" or "Phone" to be populated by the user.
I thought about using ajax events (focus, blur and keyup), but so far I have not achieved a good result. Well, here's my view:
<h:form>
<h:panelGrid columns="2">
<h:outputText value="Telefone: " />
<p:inputText id="out1" value="#{listenerView.telefone}">
<p:ajax event="focus" update="out2"
listener="#{listenerView.handleKeyEvent}"
disabled="#{listenerView.telefoneNulo}" immediate="true"/>
</p:inputText>
<h:outputText value="Celular: " />
<p:inputText id="out2" value="#{listenerView.celular}">
<p:ajax event="focus" update="out1"
listener="#{listenerView.handleKeyEvent}"
disabled="#{listenerView.celularNulo}" immediate="true" />
</p:inputText>
</h:panelGrid>
</h:form>
And my MB (listenerView.java):
public class listenerView {
private String telefone;
private String celular;
private boolean telefoneNulo;
private boolean celularNulo;
public boolean isTelefoneNulo() {
return telefoneNulo;
}
public void setTelefoneNulo(boolean telefoneNulo) {
this.telefoneNulo = telefoneNulo;
}
public boolean isCelularNulo() {
return celularNulo;
}
public void setCelularNulo(boolean celularNulo) {
this.celularNulo = celularNulo;
}
public String getTelefone() {
return telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
public String getCelular() {
return celular;
}
public void setCelular(String celular) {
this.celular = celular;
}
public void handleKeyEvent() {
if (telefone == null) {
telefoneNulo = true;
} else {
if (celular == null) {
celularNulo = true;
}
}
}
}
Any idea what I'm doing wrong? Thank you.