0

By losing the focus of the field (id="nome") method (listener="#{loginMb.criticaCamposTela}") is executed, but the attribute value (value="#{loginMb.usuario.nome}") is not updated in managed bean, the value is null. It should not be with the entered value to the validation? Why is null?

Follow the code.

Page:

<h:outputText value="Nome:" />
<p:inputText id="nome" value="#{loginMb.usuario.nome}"
    required="true" size="20" requiredMessage="Informação do nome é obrigatório.">
<p:ajax event="blur" update="idMsgNome, nome" partialSubmit="treu" process="@this"  
    immediate="true" listener="#{loginMb.criticaCamposTela}"></p:ajax>
</p:inputText>
<h:outputText id="idMsgNome" value="#{loginMb.criticaNome.value}" />

ManagedBean LoginMb:

public void criticaCamposTela(AjaxBehaviorEvent actionEvent) {
 String idComponenteTela = actionEvent.getComponent().getId();

if (idComponenteTela.equals("nome")) {

if ((this.usuario.getNome() == null)
  || ((this.usuario.getNome() != null) && (this.usuario
  .getNome().trim().length() == 0))) {

    this.criticaNome.setValue(new String(
       "O nome é um campo obrigatório."));
} else {
   this.criticaNome.setValue(new String(""));
}}

web.xml:

<context-param>
<param-name>primefaces.SUBMIT</param-name>
<param-value>partial</param-value>
</context-param>
Cœur
  • 32,421
  • 21
  • 173
  • 232
vcvmartins
  • 11
  • 1
  • 3

1 Answers1

0

Try to remove immediate="true" from p:ajax. Your ajax is processed at applay request phase and this is the reason why your field is not initialized.

partlov
  • 13,002
  • 6
  • 59
  • 76
  • Thanks. If you do not put information and change to another field (tab or mouse), the event ("onblur") does not occur and the field is not criticized. But if I type something or put blanks the validation event occurs. Do you have any idea ??? – vcvmartins Jan 21 '13 at 11:30