Primefaces inputText Ajax, return value missing the last character

0

I'm having a problem using ajax of the primefaces , also tried with ajax jsf . I have the following code snippet:

<h:panelGroup>
  <p:inputText id="skuProduto" size="20" maxlength="20"
    value="#{cadastroProdutoPapBean.produto.sku}"
    validator="#{cadastroProdutoPapBean.validaProduto}">
       <p:ajax event="keyup" execute="@this" update="mesSkuProduto, teste"/>
  </p:inputText>
  <p:message display="text" for="skuProduto" style="color:red"
                        id="mesSkuProduto" rendered="true" />
 <h:outputText id="teste"value="Aqui o teste do que foi digitado: #{cadastroProdutoPapBean.produto.sku}" style="color:red"></h:outputText>
</h:panelGroup>

I tested using:

p:ajax event="keyup"
p:ajax event="blur"

And in both situations when you bring the value typed into the method it gets missing the last character Return example:

Valor do sku digitado: 33221 

I put an outputText in the excerpt presented to verify what was being printed and returns the correct value.

Hasanyoneeverhadthis,andwouldhaveasolutiontothisproblem?

Iamusinginmybean@ViewScopedandsearchthevaluetypedwith:

System.out.println("Valor do sku digitado: " + produto.getSku());
    
asked by anonymous 23.02.2018 / 14:35

1 answer

0

I was able to solve it, it is still a solution if someone has the same problem. It turns out that I was using a method with event and making the call as follows:

public void verificar(AjaxBehaviorEvent event) {
    String valor = produto.getSku();
    System.out.println("Valor do sku digitado: " + valor);
    ...
}

When I started the data validation process I changed my method to:

 public void validaProduto(FacesContext context, UIComponent comp, Object value) { 
    String valor = produto.getSku();
    System.out.println("Valor do sku digitado: " + valor);
    ...
 }

> String with the get value declared, because for the functionality of the Validate method to work correctly, the value returned by the method must be the value of Object value . Here is how the part that receives the value coming from the page:

public void validaProduto(FacesContext context, UIComponent comp, Object value) {
  String valor = (String) value;
  System.out.println("Valor do sku digitado: " + valor);
  ...
}
    
23.02.2018 / 19:24