IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JSF Java Discussion :

champs inputtext renvoie rien


Sujet :

JSF Java

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    148
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 148
    Par défaut champs inputtext renvoie rien
    bonjour j'ai 2 champs input qui doivent contenir des dates(debut et fin).
    je souhaite obliger l'entrée d'une valeur dans le champs debut donc la pas de problème mais je n'oblige pas l'entrée de valeur dans le champs fin, ce qui fait que le champs renvoyé peut ne rien contenir. Cela pose un problème car ce champs est lié à un objet GregorianCalendar de mon bean et donc quand je soumet ma page il m'affiche ce message d'erreur
    --> Error setting property 'time' in bean of type java.util.GregorianCalendar: java.lang.NullPointerException

    Que dois-je faire pour permettre le passage d'un champs vide à une propriété de mon bean???merci

  2. #2
    Rédacteur
    Avatar de romaintaz
    Homme Profil pro
    Java craftsman
    Inscrit en
    Juillet 2005
    Messages
    3 790
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Java craftsman
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2005
    Messages : 3 790
    Par défaut
    Bonjour,

    Pourrais tu nous montrer ton code Java ainsi que JSF ?

    Merci
    Nous sommes tous semblables, alors acceptons nos différences !
    --------------------------------------------------------------
    Liens : Blog | Page DVP | Twitter
    Articles : Hudson | Sonar | Outils de builds Java Maven 3 | Play! 1 | TeamCity| CitConf 2009
    Critiques : Apache Maven

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    148
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 148
    Par défaut
    le code java

    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
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    /**
     * 
     */
    package pagecode;
     
    import com.ibm.etools.webservice.context.Context;
    import com.ibm.faces.component.html.HtmlScriptCollector;
     
    import javax.faces.application.FacesMessage;
    import javax.faces.component.html.HtmlForm;
    import javax.faces.component.html.HtmlInputText;
    import controller.CtrlApplication;
    import javax.faces.event.ValueChangeEvent;
    import javax.faces.context.FacesContext;
    import java.lang.Object;
    import java.util.Date;
    import java.util.GregorianCalendar;
    import javax.faces.component.UIComponent;
    import javax.faces.component.UIInput;
    import javax.faces.component.html.HtmlMessage;
    import com.ibm.faces.component.html.HtmlCommandExButton;
    import javax.servlet.http.*;
     
    /**
     * @author csicilia
     *
     */
    public class NewRecord extends PageCodeBase {
     
        protected HtmlScriptCollector scriptCollector1;
        protected HtmlForm form1;
        protected HtmlInputText app_id1;
        protected CtrlApplication ctrlApps;
        protected HtmlMessage message1;
        protected HtmlInputText app_code1;
        protected HtmlInputText app_lib1;
        protected HtmlInputText app_strdate1;
        protected HtmlInputText app_enddate1;
        protected HtmlCommandExButton button1;
        protected HtmlCommandExButton button2;
        protected HtmlScriptCollector getScriptCollector1() {
            if (scriptCollector1 == null) {
                scriptCollector1 = (HtmlScriptCollector) findComponentInRoot("scriptCollector1");
            }
            return scriptCollector1;
        }
     
        protected HtmlForm getForm1() {
            if (form1 == null) {
                form1 = (HtmlForm) findComponentInRoot("form1");
            }
            return form1;
        }
     
        protected HtmlInputText getApp_id1() {
            if (app_id1 == null) {
                app_id1 = (HtmlInputText) findComponentInRoot("app_id1");
            }
            return app_id1;
        }
     
        public String doButton2Action() {
            // Entrez le code Java qui s'exécute lorsque le composant est cliqué
     
            // TODO: Renvoyez la sortie qui correspond à une règle de navigation
     
            return "retour";
        }
     
        public String doButton1Action() {
            // Entrez le code Java qui s'exécute lorsque le composant est cliqué
     
            getCtrlApps().insertRecord();
            return "retour";}
     
     
        //}
     
        /** 
         * @managed-bean true
         */
        protected CtrlApplication getCtrlApps() {
            if (ctrlApps == null) {
                ctrlApps = (CtrlApplication) getManagedBean("ctrlApps");
            }
            return ctrlApps;
        }
     
        /** 
         * @managed-bean true
         */
        protected void setCtrlApps(CtrlApplication ctrlApps) {
            this.ctrlApps = ctrlApps;
        }
     
        public void valideId(){
            //getCtrlApps().validateid(app_id1);
     
        }
     
        protected HtmlMessage getMessage1() {
            if (message1 == null) {
                message1 = (HtmlMessage) findComponentInRoot("message1");
            }
            return message1;
        }
     
        protected HtmlInputText getApp_code1() {
            if (app_code1 == null) {
                app_code1 = (HtmlInputText) findComponentInRoot("app_code1");
            }
            return app_code1;
        }
     
        protected HtmlInputText getApp_lib1() {
            if (app_lib1 == null) {
                app_lib1 = (HtmlInputText) findComponentInRoot("app_lib1");
            }
            return app_lib1;
        }
     
        protected HtmlInputText getApp_strdate1() {
            if (app_strdate1 == null) {
                app_strdate1 = (HtmlInputText) findComponentInRoot("app_strdate1");
            }
            return app_strdate1;
        }
     
        protected HtmlInputText getApp_enddate1() {
            if (app_enddate1 == null) {
                app_enddate1 = (HtmlInputText) findComponentInRoot("app_enddate1");
            }
            return app_enddate1;
        }
     
        protected HtmlCommandExButton getButton1() {
            if (button1 == null) {
                button1 = (HtmlCommandExButton) findComponentInRoot("button1");
            }
            return button1;
        }
     
        protected HtmlCommandExButton getButton2() {
            if (button2 == null) {
                button2 = (HtmlCommandExButton) findComponentInRoot("button2");
            }
            return button2;
        }
        public boolean verifdate(){
            GregorianCalendar a =new GregorianCalendar();
            GregorianCalendar b =new GregorianCalendar();
            a.setTime((Date)getCtrlApps().getApplication().getApp_strdate().getTime());
            b.setTime((Date)getCtrlApps().getApplication().getApp_enddate().getTime());
            if(a.getTime().before(b.getTime()))
                    return true;
            return false;
     
        }
     
        public void handleApp_enddate1Validate(FacesContext facescontext,
                UIComponent component, Object object)
                throws javax.faces.validator.ValidatorException {
            // Tapez ici le code Java servant à la validation
     
            // void validate(FacesContext facescontext, UIComponent component, Object object) throws ValidatorException
            if(object!=null){
            FacesMessage msg= new FacesMessage("Erreur!!la date de fin est inférieure à la date de début");
            GregorianCalendar debut =new GregorianCalendar();
            debut.setTime((Date)getApp_strdate1().getValue());
             GregorianCalendar fin = new GregorianCalendar();
             fin.setTime((Date) object);
     
            if(debut.after(fin)){
                facescontext.addMessage(component.getClientId(facescontext), msg);
                ((UIInput)component).setValid(false);
            }
     
            }
     
        }
     
        public void handleApp_strdate1Validate(FacesContext facescontext,
                UIComponent component, Object object)
                throws javax.faces.validator.ValidatorException {
            FacesMessage msg = new FacesMessage("Date inférieure à la date du jour!!!");
            GregorianCalendar date=new GregorianCalendar();
            GregorianCalendar date2= new GregorianCalendar();
            date.setTime((Date) object);
            if(date.getTime().before(date2.getTime())){
                facescontext.addMessage(getApp_strdate1().getClientId(facescontext), msg);
                ((UIInput)component).setValid(false);
                                  }
     
     
        }
     
    }
    le code jsf

    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
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <%-- jsf:pagecode language="java" location="/src/pagecode/NewRecord.java" --%><%-- /jsf:pagecode --%><%@page
        language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%><%@taglib
        uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%><%@taglib
        uri="http://java.sun.com/jsf/html" prefix="h"%><html>
    <head>
    <title>NewRecord</title>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <meta name="GENERATOR"
        content="Rational Application Developer for WebSphere Software">
    <link rel="stylesheet" type="text/css" title="Style"
        href="theme/stylesheet.css">
    <script type="text/javascript"></script></head>
    <f:view>
        <body>
        <hx:scriptCollector id="scriptCollector1">
            <h:form styleClass="form" id="form1">
                <table>
                    <tbody>
                        <tr>
                            <td align="left">ID</td>
                            <td style="width: 5px">&nbsp;</td>
                            <td><h:inputText styleClass="inputText" id="app_id1"
                                value="#{ctrlApps.application.app_id}" required="true">
                                 <hx:convertNumber type="number" integerOnly="true"/>
                                <f:validateLongRange minimum="1" maximum="9999"></f:validateLongRange>
                            </h:inputText><h:message styleClass="message" id="message1" for="app_id1" ></h:message></td>
                        </tr>
                        <tr>
                            <td align="left">CODE</td>
                            <td style="width: 5px">&nbsp;</td>
                            <td><h:inputText styleClass="inputText" id="app_code1"
                                value="#{ctrlApps.application.app_code}" required="true" >
                                <hx:validateConstraint regex="^[A-Z]+$" />
                                <f:validateLength maximum="1"></f:validateLength>
                            </h:inputText><h:message for="app_code1"></h:message></td>
                        </tr>
                        <tr>
                            <td align="left">LIBRAIRIE</td>
                            <td style="width: 5px">&nbsp;</td>
                            <td><h:inputText styleClass="inputText" id="app_lib1"
                                value="#{ctrlApps.application.app_lib}" required="true">
                                <hx:validateConstraint regex="^[A-Z]+$" />
                                <f:validateLength maximum="1"></f:validateLength>
                            </h:inputText><h:message for="app_lib1"></h:message></td>
                        </tr>
                        <tr>
                            <td align="left">DATE_DEBUT</td>
                            <td style="width: 5px">&nbsp;</td>
                            <td><h:inputText styleClass="inputText" id="app_strdate1"
                                value="#{ctrlApps.application.app_strdate.time}" required="true" validator="#{pc_NewRecord.handleApp_strdate1Validate}">
                                <hx:convertDateTime pattern="dd.MM.yy" />
                                <hx:validateDateTimeRange minimum="#{now}" />
                            </h:inputText><h:message for="app_strdate1"></h:message></td>
                        </tr>
                        <tr>
                            <td align="left">DATE_FIN</td>
                            <td style="width: 5px">&nbsp;</td>
                            <td><h:inputText styleClass="inputText" id="app_enddate1"
                                value="#{ctrlApps.application.app_enddate.time}" required="false"
                                validator="#{pc_NewRecord.handleApp_enddate1Validate}">
                                <hx:convertDateTime pattern="dd.MM.yy" />
                            </h:inputText><h:message for="app_enddate1"></h:message></td>
                        </tr>
                    </tbody>
                </table>
                <br>
                <hx:commandExButton id="button1" styleClass="commandExButton"
                    type="submit" value="Valider"
                    action="#{pc_NewRecord.doButton1Action}">
                </hx:commandExButton>
                <hx:commandExButton type="submit" value="Annuler"
                    styleClass="commandExButton" id="button2"
                    action="#{pc_NewRecord.doButton2Action}" immediate="true"></hx:commandExButton>
                <br>
            </h:form>
        </hx:scriptCollector>
        </body>
    </f:view>
    </html>
    voila merci

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2008
    Messages
    148
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 148
    Par défaut
    En fait ma question est que se passe t-il quand un champs qui est censé recevoir une date en entrée qui doit initialiser une propriété date de mon managed bean est retourné vide??Bien qu'on l'ai autorisé bien sur en ne cochant pas la case valeur requise..Merci

  5. #5
    Rédacteur

    Profil pro
    Inscrit en
    Juin 2003
    Messages
    4 184
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 4 184
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    <h:inputText styleClass="inputText" id="app_id1"
                                value="#{ctrlApps.application.app_id}" required="true">
                                 <hx:convertNumber type="number" integerOnly="true"/>
                                <f:validateLongRange minimum="1" maximum="9999"></f:validateLongRange>
                            </h:inputText>
    ctrlApps.application.app_id est soit de type String, soit de type Date et dans ce cas il faut ajouter un converter..

  6. #6
    Inactif  
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    2 189
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 189
    Par défaut
    il faut tout bêtemenent je pense iniatlisalé dans tes getters ceci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
     
    Date getDateDebut() {
     
    if (dateDebut == null) {
      return new Date;
    }else {
    return dateDebut)
    }

Discussions similaires

  1. Réponses: 1
    Dernier message: 18/04/2014, 17h32
  2. Réponses: 5
    Dernier message: 16/01/2013, 19h07
  3. fonction php qui ne me renvoie rien
    Par renaudjuif dans le forum Langage
    Réponses: 10
    Dernier message: 01/08/2006, 10h27
  4. Ma requête ne me renvoie rien
    Par dessinateurttuyen dans le forum Langage SQL
    Réponses: 8
    Dernier message: 24/07/2006, 17h42
  5. [SQL-Server] mssql_query ne renvoie rien !
    Par Sophy75 dans le forum PHP & Base de données
    Réponses: 14
    Dernier message: 06/04/2006, 10h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo