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 :

Exécution procédure stockés via jsf


Sujet :

JSF Java

  1. #1
    Membre averti
    Inscrit en
    Décembre 2009
    Messages
    44
    Détails du profil
    Informations forums :
    Inscription : Décembre 2009
    Messages : 44
    Par défaut Exécution procédure stockés via jsf
    bonjour à tous,

    je suis entrain de developper une application jsf interfacé avec une base de données sql server 2005.

    pour mes requetes j'ai décidé d'utiliser les procédures stockées vue l'organisation qu'ils offrent et les possibilités de réutilisation.

    j'ai voulu faire une insertion de données dans ma base de données via un formulaire jsf à l'aide d'une procédure stockées.

    voici le code jsf faisant appel à la procédure stockées :

    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
     
     
     public String button1_action() {
            // TODO: Process the action. Return value is a navigation
            // case name where null will return to the same page.
           String nom = nomtxt.getValue().toString();
          String prenom = prenomtxt.getValue().toString();
           String cin = cintxt.getValue().toString();
           int code_client=1;
            String tel1 = teltxt.getValue().toString();
            try {
                 getSessionBean1().getClientRowSet().setCommand("exec Ps_Create_Client " + nom + "," + prenom + "," + cin + ",'chaine'," + tel1 + "," + code_client + "");
     
             } catch (SQLException ex) {
                Logger.getLogger(fiche_client.class.getName()).log(Level.SEVERE, null, ex);
            }
     
            l1.setText("enregistrement ok");
     
            return null;
        }
    Quand j'exécute le programme, ça s'exécute sans soucis mais au lieu de rajouter une seule ligne, il en rajoute deux.

    j'ai essayé de comprendre pourquoi mais en vain !!!

    Merci d'avance pour votre aide

  2. #2
    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
    Ton code n'a pas l'air très propre, il faut au moins séparer la partie DAO de la partie web.

    tu peux loguer les phases JSF pour voir si le problème vient de là, on dirait que tu utilise le binding...?

  3. #3
    Membre averti
    Inscrit en
    Décembre 2009
    Messages
    44
    Détails du profil
    Informations forums :
    Inscription : Décembre 2009
    Messages : 44
    Par défaut
    en fait j'utilise des conexions de données RowSet....

    par contre je ne comprend exactement ce que vous voulez dire par biding ??

    voici le code java entier de mon formulaire :

    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
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
     
     
    import com.sun.data.provider.impl.CachedRowSetDataProvider;
    import com.sun.rave.web.ui.appbase.AbstractPageBean;
    import com.sun.webui.jsf.component.Button;
    import com.sun.webui.jsf.component.StaticText;
    import com.sun.webui.jsf.component.TextField;
    import java.sql.SQLException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.faces.FacesException;
     
    /**
     * <p>Page bean that corresponds to a similarly named JSP page.  This
     * class contains component definitions (and initialization code) for
     * all components that you have defined on this page, as well as
     * lifecycle methods and event handlers where you may add behavior
     * to respond to incoming events.</p>
     *
     * @version Page6.java
     * @version Created on 25 déc. 2009, 15:23:01
     * @author Rachid
     */
     
    public class Page6 extends AbstractPageBean {
        // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
     
        /**
         * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
         * This method is automatically generated, so any user-specified code inserted
         * here is subject to being replaced.</p>
         */
        private void _init() throws Exception {
            clientDataProvider.setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.clientRowSet}"));
            test_insertDataProvider.setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.test_insertRowSet}"));
        }
        private TextField nomtxt = new TextField();
     
        public TextField getNomtxt() {
            return nomtxt;
        }
     
        public void setNomtxt(TextField tf) {
            this.nomtxt = tf;
        }
        private TextField prenomtxt = new TextField();
     
        public TextField getPrenomtxt() {
            return prenomtxt;
        }
     
        public void setPrenomtxt(TextField tf) {
            this.prenomtxt = tf;
        }
        private TextField cintxt = new TextField();
     
        public TextField getCintxt() {
            return cintxt;
        }
     
        public void setCintxt(TextField tf) {
            this.cintxt = tf;
        }
        private TextField teltxt = new TextField();
     
        public TextField getTeltxt() {
            return teltxt;
        }
     
        public void setTeltxt(TextField tf) {
            this.teltxt = tf;
        }
        private StaticText l1 = new StaticText();
     
        public StaticText getL1() {
            return l1;
        }
     
        public void setL1(StaticText st) {
            this.l1 = st;
        }
        private CachedRowSetDataProvider clientDataProvider = new CachedRowSetDataProvider();
     
        public CachedRowSetDataProvider getClientDataProvider() {
            return clientDataProvider;
        }
     
        public void setClientDataProvider(CachedRowSetDataProvider crsdp) {
            this.clientDataProvider = crsdp;
        }
        private CachedRowSetDataProvider test_insertDataProvider = new CachedRowSetDataProvider();
     
        public CachedRowSetDataProvider getTest_insertDataProvider() {
            return test_insertDataProvider;
        }
     
        public void setTest_insertDataProvider(CachedRowSetDataProvider crsdp) {
            this.test_insertDataProvider = crsdp;
        }
        private Button button2 = new Button();
     
        public Button getButton2() {
            return button2;
        }
     
        public void setButton2(Button b) {
            this.button2 = b;
        }
     
        // </editor-fold>
     
        /**
         * <p>Construct a new Page bean instance.</p>
         */
        public Page6() {
        }
     
        /**
         * <p>Callback method that is called whenever a page is navigated to,
         * either directly via a URL, or indirectly via page navigation.
         * Customize this method to acquire resources that will be needed
         * for event handlers and lifecycle methods, whether or not this
         * page is performing post back processing.</p>
         * 
         * <p>Note that, if the current request is a postback, the property
         * values of the components do <strong>not</strong> represent any
         * values submitted with this request.  Instead, they represent the
         * property values that were saved for this view when it was rendered.</p>
         */
        @Override
        public void init() {
            // Perform initializations inherited from our superclass
            super.init();
            // Perform application initialization that must complete
            // *before* managed components are initialized
            // TODO - add your own initialiation code here
     
            // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
            // Initialize automatically managed components
            // *Note* - this logic should NOT be modified
            try {
                _init();
            } catch (Exception e) {
                log("Page6 Initialization Failure", e);
                throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
            }
     
            // </editor-fold>
            // Perform application initialization that must complete
            // *after* managed components are initialized
            // TODO - add your own initialization code here
        }
     
        /**
         * <p>Callback method that is called after the component tree has been
         * restored, but before any event processing takes place.  This method
         * will <strong>only</strong> be called on a postback request that
         * is processing a form submit.  Customize this method to allocate
         * resources that will be required in your event handlers.</p>
         */
        @Override
        public void preprocess() {
        }
     
        /**
         * <p>Callback method that is called just before rendering takes place.
         * This method will <strong>only</strong> be called for the page that
         * will actually be rendered (and not, for example, on a page that
         * handled a postback and then navigated to a different page).  Customize
         * this method to allocate resources that will be required for rendering
         * this page.</p>
         */
        @Override
        public void prerender() {
        }
     
        /**
         * <p>Callback method that is called after rendering is completed for
         * this request, if <code>init()</code> was called (regardless of whether
         * or not this was the page that was actually rendered).  Customize this
         * method to release resources acquired in the <code>init()</code>,
         * <code>preprocess()</code>, or <code>prerender()</code> methods (or
         * acquired during execution of an event handler).</p>
         */
        @Override
        public void destroy() {
            clientDataProvider.close();
            test_insertDataProvider.close();
        }
     
        /**
         * <p>Return a reference to the scoped data bean.</p>
         *
         * @return reference to the scoped data bean
         */
        protected SessionBean1 getSessionBean1() {
            return (SessionBean1) getBean("SessionBean1");
        }
     
        /**
         * <p>Return a reference to the scoped data bean.</p>
         *
         * @return reference to the scoped data bean
         */
        protected RequestBean1 getRequestBean1() {
            return (RequestBean1) getBean("RequestBean1");
        }
     
        /**
         * <p>Return a reference to the scoped data bean.</p>
         *
         * @return reference to the scoped data bean
         */
        protected ApplicationBean1 getApplicationBean1() {
            return (ApplicationBean1) getBean("ApplicationBean1");
        }
     
        public String button1_action() {
            // TODO: Process the action. Return value is a navigation
            // case name where null will return to the same page.
           String nom = nomtxt.getValue().toString();
          String prenom = prenomtxt.getValue().toString();
           String cin = cintxt.getValue().toString();
     
     
            int code_client=1;
            String tel1 = teltxt.getValue().toString();
            try {
                getSessionBean1().getClientRowSet().setCommand("exec Ps_Create_Client " + nom + "," + prenom + "," + cin + ",'said'," + tel1 + "," + code_client + "");
     
                 } catch (SQLException ex) {
                Logger.getLogger(fiche_client.class.getName()).log(Level.SEVERE, null, ex);
            }
     
            l1.setText("enregistrement ok");
     
            return null;
        }
    }
    et voici la partie en jsp :

    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
     
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- 
        Document   : Page6
        Created on : 25 déc. 2009, 15:23:01
        Author     : scania
    -->
    <jsp:root version="2.1" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:webuijsf="http://www.sun.com/webui/webuijsf">
        <jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
        <f:view>
            <webuijsf:page id="page1">
                <webuijsf:html id="html1">
                    <webuijsf:head id="head1">
                        <webuijsf:link id="link1" url="/resources/stylesheet.css"/>
                    </webuijsf:head>
                    <webuijsf:body id="body1" style="-rave-layout: grid">
                        <webuijsf:form id="form1">
                            <webuijsf:textField binding="#{Page6.nomtxt}" id="nomtxt" label="Nom" style="left: 72px; top: 48px; position: absolute"/>
                            <webuijsf:textField binding="#{Page6.prenomtxt}" id="prenomtxt" label="Prénom" style="left: 72px; top: 96px; position: absolute"/>
                            <webuijsf:textField binding="#{Page6.cintxt}" id="cintxt" label="CIN" style="left: 72px; top: 144px; position: absolute"/>
                            <webuijsf:textField binding="#{Page6.teltxt}" id="teltxt" label="Téléphone" style="left: 408px; top: 48px; position: absolute"/>
                            <webuijsf:staticText binding="#{Page6.l1}" id="l1" style="color: green; font-size: 18px; font-weight: bold; left: 504px; top: 96px; position: absolute"/>
                            <webuijsf:button actionExpression="#{Page6.button1_action}" id="button1" style="position: absolute; left: 96px; top: 240px" text="Sauvegarder"/>
                            <webuijsf:button actionExpression="#{Page6.button2_action}" binding="#{Page6.button2}" id="button2"
                                style="position: absolute; left: 288px; top: 264px" text="sauvegarde2"/>
                        </webuijsf:form>
                    </webuijsf:body>
                </webuijsf:html>
            </webuijsf:page>
        </f:view>
    </jsp:root>
    je signale que j'utilise netbeans comme IDE.

    Merci

  4. #4
    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
    le binding c'est ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     binding="#{Page6.nomtxt}"
    tu peux utiliser simplement des h:inputText et h:commandButton standards, le binding n'est pas fait pour ça, plutôt pour générer dynamiquement un composant.

  5. #5
    Membre averti
    Inscrit en
    Décembre 2009
    Messages
    44
    Détails du profil
    Informations forums :
    Inscription : Décembre 2009
    Messages : 44
    Par défaut
    bonjour

    j'ai essayé d'utiliser des composants standard jsp et il m'est avéré que meme ces composant ont besoin du binding pour qu'ils soient reconnu au niveau du code java...

  6. #6
    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
    tu veux dire JSF, avant de commencer..et pour comprendre ce que tu fais, il vaut mieux commencer par lire un peu de documentation, tu trouvera pas mal de tutoriels ici même.

  7. #7
    Invité de passage
    Inscrit en
    Mars 2010
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Mars 2010
    Messages : 1
    Par défaut
    Citation Envoyé par Sniper37 Voir le message
    tu veux dire JSF, avant de commencer..et pour comprendre ce que tu fais, il vaut mieux commencer par lire un peu de documentation, tu trouvera pas mal de tutoriels ici même.

    Bonjour,
    dans la méthode " setCommand " tu n'as pas bien écrire la requête sql
    exemple
    setCommand("insert into table.id ....")

Discussions similaires

  1. [PDO] [PHP 5.3][ZEND][PDO] Exécution d'une procédure stockée via PDO et Zend
    Par daav14 dans le forum PHP & Base de données
    Réponses: 6
    Dernier message: 11/10/2010, 20h56
  2. Exécution procédure stockés via jsf
    Par scania113H dans le forum JSF
    Réponses: 3
    Dernier message: 04/01/2010, 14h43
  3. [VB.NET]Performance exécution procédure stockée
    Par Franck2mars dans le forum Windows Forms
    Réponses: 3
    Dernier message: 29/05/2006, 16h11
  4. [SQL SERVER 2K]Droits d'exécution procédure stockée
    Par Franck2mars dans le forum MS SQL Server
    Réponses: 7
    Dernier message: 16/05/2006, 15h01
  5. Réponses: 4
    Dernier message: 25/10/2005, 10h36

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