Primefaces inputText Ajax, returns value missing the last character

Asked

Viewed 125 times

0

I’m having a problem using the ajax of primefaces, I also tried with the ajax of 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 bringing the typed value to the method it remains missing the last character Example of the return:

Valor do sku digitado: 33221 

I put an outputText in the shown snippet to check what was being printed and returns the correct value. inserir a descrição da imagem aqui

Someone’s been through this, and there would be a solution to this problem?

I’m using it on my bean @Viewscoped and search the value typed with:

System.out.println("Valor do sku digitado: " + produto.getSku());
  • Enter Mbean’s code then, which you are bringing without the last digit.

  • My bean is quite large, so I put the relevant information of the bean.

  • Where is the system out that prints the value with one digit less? Puts the context in which it is inserted.

  • Hi Giuliana, I managed to solve the problem, I thought it was on the jsf page but actually it was in the method, silly that I was doing. I’ll make an answer with the solution.

  • That’s why I needed the Mbean post, you know? Only with what you exposed in your question could not know the problem. Put Mbean’s code in the question.

  • Hi Giuliana, thank you for your interest in helping, as you thought it was not a problem in the method and because it contains a lot of information I thought there was no need, my mistake. But in the answer I specified the problem and the solution!

Show 1 more comment

1 answer

0


I managed to solve, follow solution in case someone goes through the same problem. Turns out I was using an event method 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);
    ...
 }

That is the problem, because when using the Validator of inputText I have the value of Object value and not of a String with the value of get declared, because for the functionalities of the method Validate function correctly, the value returned by the method has to be the value of the Object value. It follows below as it was 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);
  ...
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.