<p:chips><p:ajax event="itemAdd"> throws exception that itemAdd event is not supported

27 views Asked by At

I'm seeking assistance in understanding the integration of p:chips with p:ajax.

Upon the completion of a user typing a new two-letter acronym, I aim to validate it within my Managed Bean (MB). This validation is crucial to prevent the duplication of data in the p:chips field. Below, you'll find snippets of both my XHTML code and Managed Bean (MB):

<div class="row">
    <div class="col-12">
        <p:chips id="intinerario" 
                 value="#{MB.dto.ufsper}" 
                 maxlength="2"
                 styleClass="form-control-chips w-100 text-uppercase" 
                 style="height: 100px; overflow-y: auto;" 
                 widgetVar="chipsWidget">

            <p:ajax event="itemAdd" 
                    listener="#{MB.validarEstadosRepetidosA}" 
                    update="intinerario" />

        </p:chips>

    </div>
</div>
  public void validarEstadosRepetidosAjax() {
        List<String> estadosAdicionados = dto.getUfsper();
    
        if (temEstadosDuplicados(estadosAdicionados)) {
           
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Não é permitido adicionar o mesmo estado mais de uma vez.", null));
        }
    }
    

    private boolean temEstadosDuplicados(List<String> estados) {
        Set<String> estadosSet = new HashSet<>();
    
        for (String estado : estados) {
            if (!estadosSet.add(estado)) {
              
                return true;
            }
        }
    
        return false;
    }

ERROR 63409 --- [nio-8081-exec-5] o.a.c.c.C.[.[.[.[facesServlet] : Servlet.service() for servlet [facesServlet] in context with path [/mytracking] threw exception [/pages/private/moduloFiscal/mdfFiscal/edit/tab/tabPercursoMdf.xhtml @100,32 <p:ajax> Event:itemAdd is not supported.] with root cause

1

There are 1 answers

0
Jasper de Vries On

Please read the documentation on the Chips Ajax behavior events. The event itemAdd is not supported (as stated in the exception). You probably want to use the valueChange event (which is the default).