PrimeFaces autoComplete weird behavior

A few weeks ago, while changing the behavior of an auto-complete field we have in our system, I came across a very weird bug. The field was supposed to suggest a list of Technicians, based on the name the user typed.

I was asked to have it accept not only the name of the Technician but also their ids.

To make the long story short: we are using a PrimeFaces AutoComplete component with the forceSelection flag set to true. The problem was that even tough the user did not selected any of the suggestions on the list, the value he typed was still being submitted to the form.

At first this was not a problem, because our Converter is using the Technician id, and when searching for a name, there was no match. But when the search includes the id, undesired thing happens, i.e. the field which as supposed to be empty, was filled with the Technician's information whose id the user typed.

With the help of Firebug, I found out that the hidden input Primefaces uses to implement the auto-completion, was not being cleaned when none of the suggestions was picked, thus, submitting a value the user didn't know was there.

To solve the problem, I hacked into Primefaces's jar, and, after formatting the autocomplete.js with the help of my friend Eclipse, I found this line:

jQuery(this).val("");

On a lucky/educated guess, I added the following line below that one:

jQuery(a.jqh).val("");

After repacking the jar, the problem was gone. I am not sure if this is a bug or the correct behavior, but it happened in Primefaces version 2.2.1.

Nenhum comentário:

Postar um comentário