0

can you help me please... below you find the codes I used to display a message concerning the availability of an email ... all working correctly except the display ...Thank you for the answer...

Dao

public boolean checkAvailable (String designation) {
        Assert.notNull(designation);
        Query req = getEntityManager().createQuery("select count(*) from "+ getPersistentClass().getName()+" a where a.email = :x");
        req.setParameter("x", designation);
        Long count = (Long) req.getSingleResult();
        
        return count < 1;
    }

Bean

public boolean checkAvailable(AjaxBehaviorEvent event) {
        
        InputText inputText = (InputText) event.getSource();
        String value = (String) inputText.getValue();

        boolean available = eleveService.checkAvailable(value);
            
        if (!available) {
            FacesMessage message = constructErrorMessage(null, String.format("Email '%s' est disponible", value));
            getFacesContext().addMessage(event.getComponent().getClientId(), message);
        } else {
            FacesMessage message = constructInfoMessage(null, String.format("Email '%s' est non disponible", value));
            getFacesContext().addMessage(event.getComponent().getClientId(), message);
        }   
        return available;
        
    }

primefaces

<h:panelGroup>
    <h:outputText value="Email:" />
    <h:outputText style="color:red" value="*  " />
</h:panelGroup>
<p:inputText id="email" value="#{eleveMB.eleve.email}"
            style="width: 250px; height:18px" required="true"
            title="Saisir l'email de l'eleve">
            <f:ajax event="keyup" update="emailMsg" global="false"
            listener="#{eleveMB.checkAvailable}" />
</p:inputText>
<h:panelGroup>
            <p:message id="emailMsg" for="email" />
            <p:tooltip for="email" styleClass="tooltip" showEvent="focus"
                        hideEvent="blur" />
</h:panelGroup> 
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
  • Are you sure that you need a call for every key up event? What's your general desired result? Else try with ` ` without the update in the ajax – WoAiNii Feb 20 '21 at 12:57
  • Thanks for the answer, yes I did it ...and also `` I have changed the update in ajax ...And it work .... – Ines Zerriaa Feb 20 '21 at 19:17
  • You are not linking the message to the component, assuming that the `null` in your `constructErrorMessage` is the component id. – Jasper de Vries Feb 21 '21 at 08:43
  • thank you for your answers... I resolved the problem by theses codes in primefaces ` ` and `` – Ines Zerriaa Feb 21 '21 at 10:46

0 Answers0