0

I have a p:autoComplete component where I want to show links based on the selected item. A visual example:

To do so, I update a component when the value of the p:autoComplete changes. Part of this is having a p:ajax listener on the clear event. This works great as long as the auto complete component is not required. When it is required, I run into a required validator message which is displayed.

So, I'm trying to skip validation when a request is triggered by the clear event. Inspired by JSF skip Required-Validation without immediate=true, I've tried:

<p:autoComplete required="#{param['javax.faces.source'] ne component.clientId and ...}" ...> <p:ajax event="clear" update="..."/> </p:autoComplete> 

and:

<p:autoComplete required="#{empty param['primefaces.resetvalues'] and ...}" ...> <p:ajax event="clear" update="..." resetValues="true"/> </p:autoComplete> 

but both are not working. Is what I want at all possible? Please note that the component is used as a custom tag, so I cannot hardcode the full clientId.

I'm using JSF 2.3 (bundled with a recent Payara 5).

    1 Answer 1

    1

    The ajax event type is passed as request parameter with name of javax.faces.behavior.event.

    So this should do:

    <p:autoComplete required="#{param['javax.faces.behavior.event'] ne 'clear'}"> 

    It's wise to doublecheck if this is invoked on the very component itself else it'll also be skipped when the very ajax event happens to be fired by another component:

    <p:autoComplete required="#{not ( param['javax.faces.source'] eq component.clientId and param['javax.faces.behavior.event'] eq 'clear' )}"> 
    3
    • But then the param['javax.faces.source'] ne component.clientId I've tried should have worked, right? That check should pass any Ajax request by the component, not just clear.CommentedOct 12, 2023 at 14:40
    • 1
      Hmm, works for me. Perhaps #{component} is in your context not the one you expected it is?
      – BalusC
      CommentedOct 12, 2023 at 16:58
    • I was able to prefix the auto complete label with #{component.clientId}, so the implicit object works as expected. Going to accept your answer as it works for you. Will fix my issue with a workaround.CommentedOct 13, 2023 at 9:05

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.