1
Hello! I’m having trouble getting a validation. Here’s the thing... I have a form made inside the components Primefaces 4.0 that has the fields "Cellular" and "Telephone". My intention is that the form starts with these two fields enabled, but when the mouse cursor focuses on one of them, the other is disabled, causing only "Mobile" or "Phone" to be filled by the user.
I thought about using ajax events (Focus, Blur and keyup ), but so far I did not get a good result. Well, follow 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.
good evening. Gee, thanks for showing me where I was going wrong. I really screwed up with the field
disabled
. But if it’s not too upsetting, I might ask why to remove theimmediate
? It has some negative influence generally or is not part of some good practice?– Alessandra
In this link: http://moacirrf.com.br/blog/? p=89, there is a very complete explanation
– hlucasfranca
Thank you. It was very enlightening! The article you sent is very good!
– Alessandra