1

I want to show a primefaces overlay with search suggestions using p:ajax like following:

<p:inputText value="#{bean.input}" required="true" 
    validatorMessage="Add at least 3 characters">
    <f:validateLength minimum="3" maximum="64"/>
    <p:ajax event="keyup" delay="200" process="@this" 
        listener="#{bean.createSuggestions()}"
        update="overlay"
        oncomplete="showOverlay()"/>
</p:inputText>

The problem is, that no validation takes place.

I could use javascript onstart handler and check input again as a workaround.

djmj
  • 5,579
  • 5
  • 54
  • 92

1 Answers1

3

Execute p:ajax only if input is valid

That's only possible if you validate in client side, as you already figured for the workaround.

The alternative would be to execute oncomplete only when there's no validation error.

oncomplete="if (args &amp;&amp; !args.validationFailed) showOverlay()"

The doublecheck and ugly XML escaping is necessary for reasons mentioned here: Keep p:dialog open when a validation error occurs after submit.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555