Bonjour à tous,

Voilà j'expose mon problème, je suis actuellement sur un projet en jsf et j'utilise PrimeFaces et dans ce cas précis j'aimerai soumettre une vérification entre deux dates et bloquer l'édition avec un petit message en cas d'échec mais il se révèle que l'édition se fait malgré le test de vérification. Donc j'aimerai savoir comment bloqué une édition dans un dataTable quand le test est faux.

Code de mon entité Autorisation :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package com.gestionGVI.metier;
 
import java.io.Serializable;
import java.util.Calendar;
import java.util.Objects;
 
/**
 * @author Simon
 */
public class Autorisation implements Serializable {
 
    private Long id;
    private Calendar dateDeb;
    private Calendar dateFin;
    private Personne personne;
    private Structure structure;
 
    public Autorisation() {
    }
 
 
    public Autorisation(Calendar dateDeb, Calendar dateFin, Personne personne, Structure structure) {
        this.dateDeb = dateDeb;
        this.dateFin = dateFin;
        this.personne = personne;
        this.structure = structure;
    }
 
 
    public Long getId() {
        return id;
    }
 
    public void setId(Long id) {
        this.id = id;
    }
 
    public Calendar getDateDeb() {
        return dateDeb;
    }
 
    public void setDateDeb(Calendar dateDeb) {
        this.dateDeb = dateDeb;
    }
 
    public Calendar getDateFin() {
        return dateFin;
    }
 
    public void setDateFin(Calendar dateFin) {
        this.dateFin = dateFin;
    }
 
    public Personne getPersonne() {
        return personne;
    }
 
    public void setPersonne(Personne personne) {
        this.personne = personne;
    }
 
    public Structure getStructure() {
        return structure;
    }
 
    public void setStructure(Structure structure) {
        this.structure = structure;
    }
 
    @Override
    public int hashCode() {
        int hash = 7;
        hash = 29 * hash + Objects.hashCode(this.id);
        hash = 29 * hash + Objects.hashCode(this.dateDeb);
        hash = 29 * hash + Objects.hashCode(this.dateFin);
        hash = 29 * hash + Objects.hashCode(this.personne);
        hash = 29 * hash + Objects.hashCode(this.structure);
        return hash;
    }
 
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Autorisation other = (Autorisation) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        if (!Objects.equals(this.dateDeb, other.dateDeb)) {
            return false;
        }
        if (!Objects.equals(this.dateFin, other.dateFin)) {
            return false;
        }
        if (!Objects.equals(this.personne, other.personne)) {
            return false;
        }
        if (!Objects.equals(this.structure, other.structure)) {
            return false;
        }
        return true;
    }
 
    @Override
    public String toString() {
        return "Autorisation{" + "id=" + id + ", dateDeb=" + dateDeb + ", dateFin=" + dateFin + ", personne=" + personne + ", structure=" + structure + '}';
    }
 
 
}

Code de ma page autorisation.xhtm :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head> 
        <title>Autorisation</title>
 
        <!-- A terminer pour l'édition -->
    </h:head>
    <h:body>
        <ui:composition template="layout.xhtml">                     
            <ui:define name="content">
                <h:form id="formAutorisationView">
                    <script src="localeFr.js" type="text/javascript"/>
                    <p:panel header="Autorisation">
                    <p:messages id="msgs"/>
                    <p:dataTable var="autorisation" value="#{autorisationView.autorisations}" editable="true" rows="3"
                                 paginator="true"
                                 paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                 currentPageReportTemplate="Page: {currentPage}/{totalPages}"
                                 rowsPerPageTemplate="1,2,3">
                        <p:ajax event="rowEdit" listener="#{autorisationView.onRowEdit(autorisation)}" update=":formAutorisationView:msgs"  />
                        <p:ajax event="rowEditCancel" listener="#{autorisationView.onRowCancel}" update=":formAutorisationView:msgs" />
                        <!-- var permet d'utiliser les methodes de l'objet var -->
                        <p:column headerText="Id">
                            <h:outputText value="#{autorisation.id}" />                  
                        </p:column>
                        <p:column headerText="Personne">
                            <p:cellEditor>
                                <f:facet name="output">
                                    <h:outputText value="#{autorisation.personne.nom}" />
                                </f:facet>
                                <f:facet name="input"> 
                                    <h:selectOneMenu value="#{autorisation.personne}"  converter="#{LeConverterDe}" style="width:100%">
                                        <f:selectItems value="#{autorisationView.personnes}" var="personne" itemLabel="#{personne.nom}" itemValue="#{personne}" />
                                    </h:selectOneMenu>
                                </f:facet>   
                            </p:cellEditor>                       
                        </p:column>
                        <p:column headerText="Structure">
                            <p:cellEditor>
                                <f:facet name="output">
                                    <h:outputText value="#{autorisation.structure.nom}" />
                                </f:facet>
                                <f:facet name="input"> 
                                    <h:selectOneMenu value="#{autorisation.structure}"  converter="#{LeConverterDe}" style="width:100%">
                                        <f:selectItems value="#{autorisationView.structures}" var="structure" itemLabel="#{structure.nom}" itemValue="#{structure}" />
                                    </h:selectOneMenu>
                                </f:facet>   
                            </p:cellEditor>                    
                        </p:column> 
                        <p:column headerText="Date début">
                            <p:cellEditor>
                                <f:facet name="output">
                                    <h:outputText value="#{autorisation.dateDeb.time}" >
                                        <f:convertDateTime  pattern="dd/MM/yyyy HH:mm" timeZone="Europe/Paris"/>
                                    </h:outputText> 
                                </f:facet>
                                <f:facet name="input"> 
                                    <p:calendar id="dateDebut"  value="#{autorisation.dateDeb.time}" locale="fr" pattern="dd/MM/yyyy HH:mm" mindate="#{autorisationView.calMin.time}" timeZone="Europe/Paris" required="true" requiredMessage="Veuillez rentrer une date de debut" label="Date de debut">
                                        <f:ajax render="dateFin" listener="#{autorisationView.isEnable()}" event="blur" execute="@this" />                                        
                                    </p:calendar>
                                </f:facet>   
                            </p:cellEditor>                    
                        </p:column>
                        <p:column headerText="Date fin">
                            <p:cellEditor>
                                <f:facet name="output">
                                    <h:outputText value="#{autorisation.dateFin.time}" >
                                        <f:convertDateTime  pattern="dd/MM/yyyy HH:mm" timeZone="Europe/Paris" />
                                    </h:outputText> 
                                </f:facet>
                                <f:facet name="input"> 
                                    <p:calendar id="dateFin" disabled="#{autorisationView.disable}" value="#{autorisation.dateFin.time}" locale="fr" pattern="dd/MM/yyyy HH:mm" mindate="#{autorisation.dateDeb.time}" timeZone="Europe/Paris" required="true" requiredMessage="Veuillez rentrer une date de fin" label="Date de fin"/>
                                </f:facet>   
                            </p:cellEditor>                    
                        </p:column>                        
                        <p:column style="width:52px">
                            <f:facet name="header">Editer</f:facet>    
                            <p:rowEditor />
                        </p:column>
                        <p:column>
                            <f:facet name="header">Supprimer</f:facet>
                            <p:commandButton id="deleteButton"  partialSubmit="true" update="@form" process="@this" action="#{autorisationView.supprimer(autorisation)}" icon="ui-icon-trash"/>
                        </p:column>                        
                    </p:dataTable>
                    </p:panel>
                </h:form>
                <br/>
                <h:form>
                    <div align="center">
                            <p:commandButton id="ajouterAutorisation" value="Créer une autorisation" action="ajoutAutorisation.xhtml?faces-redirect=true" icon="ui-icon-plus"/>
                        <p:commandButton id="ajouterPersonne" value="Créer une personne" action="ajoutPersonne.xhtml" icon="ui-icon-plus"/>
                        <p:commandButton id="ajouterStructure" value="Créer une structure" action="ajoutStructure.xhtml" icon="ui-icon-plus"/>                        
                    </div>
                </h:form>
            </ui:define>
        </ui:composition>
    </h:body>
</html>
Mon code pour l'édition avec le message à afficher :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
public void onRowEdit(Autorisation autorisation) throws Exception {
        Calendar dateDebAutorisartion=autorisation.getDateDeb() ;
        Calendar dateFinAutorisartion =autorisation.getDateFin() ;
        Personne personneAutorisation = autorisation.getPersonne();
        Structure structureAutorisation = autorisation.getStructure();
        if (dateDebAutorisartion.equals(dateFinAutorisartion)) {
            FacesContext.getCurrentInstance().addMessage(null,new FacesMessage("Erreur date identique"));
        }
}
J'aimerai donc bloquer l'édition si je passe dans cette condition
Merci pour vos prochaines réponses