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 :

Récupérer le contenu d'une ligne dans datatable


Sujet :

JSF Java

  1. #1
    Membre du Club
    Femme Profil pro
    Inscrit en
    Mai 2011
    Messages
    177
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Mai 2011
    Messages : 177
    Points : 50
    Points
    50
    Par défaut Récupérer le contenu d'une ligne dans datatable
    bonjour,
    j'ai une datatable qui contient une liste d'objets( liste des compagnes) qui attendent d'etre validé.pour ceci j'ai ajouter un champs qui correspond à un bouton qui permet de valider ou de rejeter une compagne.j'ai créé la méthode qui permet la validation et je l'ai mis dans action lister du bouton mais ça ne marche pas.le bouton ne peut pas accéder à la compagne souhaité.

    voici mon code

    valide.xhtml
    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
    <?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://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:p="http://primefaces.org/ui">
     
        <h:head>
            <title> Liste des compagnes </title>
            <link rel="stylesheet" href="css/style_all2.css" type="text/css" media="screen" />
     
     
     
            <!-- to choose another color scheme uncomment one of the foloowing stylesheets and wrap styl1.css into a comment -->
            <link rel="stylesheet" href="css/style1hay.css" type="text/css" media="screen" />
            <link rel="stylesheet" href="css/jquery-ui.css" type="text/css" media="screen" />
            <link rel="stylesheet" href="css/jquery.wysiwyg.css" type="text/css" media="screen" /> 
     
        </h:head>
        <h:body>
     
     
            <h:form id="form">  
     
                <p:dataTable value="#{compagne.valide}" var="o" paginator="true" rows="10" 
                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                             rowsPerPageTemplate="3,5,10" widgetVar="50" style="width: auto;" >
                    <f:facet name="header">  
                        Liste des compagnes   
                    </f:facet>
     
                    <p:column sortBy="#{o.user}" width="100px">
                        <f:facet name="header">  
                            <h:outputText value="Societe" />  
                        </f:facet>
                        <h:outputText value="#{o.user}"/>
                    </p:column>
                    <p:column filterBy="#{o.header}" width="120px">
                        <f:facet name="header">  
                            <h:outputText value="En tete" />  
                        </f:facet>
                        <h:outputText value="#{o.header}"/>
                    </p:column>
                    <p:column sortBy="#{o.texte_sms}" width="360px">
                        <f:facet name="header">  
                            <h:outputText value="Message SMS" />  
                        </f:facet>
                        <h:outputText value="#{o.texte_sms}"/>
                    </p:column>
     
                    <p:column sortBy="#{o.date}" width="300px">
                        <f:facet name="header">  
                            <h:outputText value="Date d'envoi" />  
                        </f:facet>
                        <h:outputText value="#{o.date}"/>
                    </p:column>
     
                    <p:column sortBy="#{o.status}" width="100px">
                        <f:facet name="header">  
                            <h:outputText value="Status" />  
                        </f:facet>
                        <h:outputText value="#{o.status}"/> 
                    </p:column>
     
                    <p:column sortBy="#{o.solde}" width="100px">
                        <f:facet name="header">  
                            <h:outputText value="Nombre de SMS" />  
                        </f:facet>
                        <h:outputText value="#{o.solde}"/>
                    </p:column>
     
                     <p:column sortBy="#{o.relatedtable}" width="100px">
                        <f:facet name="header">  
                            <h:outputText value="relatedTable" />  
                        </f:facet>
                        <h:outputText value="#{o.relatedtable}"/>
                    </p:column>
     
                    <p:column  width="100px">
                        <f:facet name="header">  
                            <h:outputText value="valider" />  
                        </f:facet>
                        <p:commandButton value="valider" actionListener="#{compagne.editValide}"  >
                            <f:setPropertyActionListener value="#{o}"  target="#{compagne.selectedCompagne}" />
                        </p:commandButton>
                    </p:column>
     
                </p:dataTable>
            </h:form>
     
        </h:body>
    </html>
    voici le bean
    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
    package beans;
     
    import dao.Database1;
    import dao.UserDAO2;
    import java.io.Serializable;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.Date;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.RequestScoped;
    import javax.faces.bean.SessionScoped;
    import javax.faces.component.UIComponent;
    import javax.faces.component.html.HtmlDataTable;
    import javax.faces.event.ActionEvent;
    import javax.servlet.http.HttpSession;
    import org.primefaces.model.SelectableDataModel;
    import javax.faces.model.ListDataModel;
    import org.primefaces.event.SelectEvent;
    import org.primefaces.event.UnselectEvent;
     
    /**
     *
     * @author stoner2008
     */
    @ManagedBean(name = "compagne")
    @SessionScoped
    public class CompagneBean implements Serializable {
     
        private String user, status, relatedtable;
        private int solde;
        private String rec_date, texte_sms, header, date;
        private String idv;
        private CompagneBean selectedCompagne;
     
      //getters & setters
        public ArrayList<CompagneBean> getMessages() throws ParseException {
     
            HttpSession session = com.beans.Util.getSession();
            session.setAttribute("datedebut", format_dateDebut());
            session.setAttribute("datefin", format_dateFin());
            session.setAttribute("user", user);
     
            return UserDAO2.getCompagne();
        }
     
        public ArrayList<CompagneBean> getvalide() throws ParseException {
     
            return UserDAO2.getCompagne2();
        }
     
        public static void validateTable(String table, Connection dbcon) {
            try {
                Statement stmt = dbcon.createStatement();
                stmt.execute("UPDATE " + table + " set status='valide' ");
                dbcon.commit();
            } catch (SQLException sqle) {
                System.out.println("erreur SQL au niveau de UpdateReceivederr:" + sqle.getMessage());
                try {
                    dbcon.rollback();
                } catch (Exception e) {
                    System.out.println(e.getMessage());
                }
            }
     
            // validateBulk(findCompagne(table, dbcon), dbcon);
     
        }
     
     public static void validateBulk(String id, Connection dbcon) {
            try {
                Statement stmt = dbcon.createStatement();
                stmt.execute("UPDATE bulk set status='valide' where \"idBulk\"=" + id + "");
                dbcon.commit();
            } catch (SQLException sqle) {
                System.out.println("erreur SQL au niveau de UpdateReceivederr:" + sqle.getMessage());
                try {
                    dbcon.rollback();
                } catch (Exception e) {
                    System.out.println(e.getMessage());
                }
            }
     
        }
     
     public void editValide() {
            Connection conn = Database1.getConnection();
            System.out.println("--------- edit valide ------");
            System.out.println("--------- gaz ------ " + selectedCompagne);
            System.out.println("--------- this ------ " + selectedCompagne.relatedtable);
            System.out.println("--------- this ------ " + this.relatedtable);
            System.out.println("--------- related ------ " + relatedtable);
            System.out.println("--------- fedgerdg  ------ " + idv);
            System.out.println("--------- related ------ " + this.idv);
            CompagneBean.validateBulk(id, conn);
     
        }
    }
    voici userDAO2.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
     
     
    public static ArrayList<CompagneBean> getCompagne2() {
            try {
     
                //System.out.println("date de edbut this "+this.datedebut);
    //            String date_debut = format_dateDebut(datedebut);
                System.out.println("select * from bulk ");
                Connection con = Database1.getConnection();
                PreparedStatement ps = con.prepareStatement("select * from bulk ");
                ArrayList<CompagneBean> al = new ArrayList<CompagneBean>();
                ResultSet rs = ps.executeQuery();
                boolean found = false;
                while (rs.next()) {
                    CompagneBean e = new CompagneBean();
                    e.setIdv(rs.getString("idbulk"));
                    e.setUser(rs.getString("societe"));
                    e.setHeader(rs.getString("header_bulk"));
                    e.setTexte_sms(rs.getString("texte_sms"));
                    e.setDate(rs.getString("rec_date"));
                    e.setStatus(rs.getString("status"));
                     e.setRelatedtable(rs.getString("relatedtable"));
                    e.setSolde(Integer.parseInt(rs.getString("solde")));
                    al.add(e);
                    found = true;
                }
                rs.close();
                if (found) {
                    System.out.println("found items");
                    return al;
                } else {
                    System.out.println("nothing is found");
                    return null; // no entires found
                }
            } catch (Exception e) {
                System.out.println("Error In getCompagne() -->" + e.getMessage());
                return (null);
            }
        }

    merci pour votre aide

  2. #2
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    Peux-tu nous afficher l' erreur pour qu'on sache ce qui ne va pas.
    Eric

  3. #3
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    Regardes c' est getValide () V et non v

  4. #4
    Membre du Club
    Femme Profil pro
    Inscrit en
    Mai 2011
    Messages
    177
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Mai 2011
    Messages : 177
    Points : 50
    Points
    50
    Par défaut
    Citation Envoyé par jeffray03 Voir le message
    Peux-tu nous afficher l' erreur pour qu'on sache ce qui ne va pas.
    Eric
    si je clique sur le bouton valider ça marche pas.l'execution de la méthode editvalide dans actionListner)
    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
    --------- edit valide ------
    --------- gaz ------ null
    déc. 26, 2013 3:54:26 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute
    WARNING: java.lang.NullPointerException
    javax.el.ELException: java.lang.NullPointerException
    	at org.apache.el.parser.AstValue.invoke(AstValue.java:291)
    	at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
    	at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149)
    	at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    	at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:818)
    	at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    	at javax.faces.component.UIData.broadcast(UIData.java:1108)
    	at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    	at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:611)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    	at java.lang.Thread.run(Thread.java:724)
    Caused by: java.lang.NullPointerException
    	at beans.CompagneBean.editValide(CompagneBean.java:272)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
    	... 31 more

  5. #5
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    Il ya une autre facon de faire: remplace ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <p:commandButton value="valider" actionListener="#{compagne.editValide}"  >
                            <f:setPropertyActionListener value="#{o}"  target="#{compagne.selectedCompagne}" />
                        </p:commandButton>
    Par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <p:commandButton value="valider" actionListener="#{compagne.editValide(o)}"  >
     
                        </p:commandButton>
    Et tu inseres
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    public void editValide(Compagne compagne) {
           selectedCompagne=compagne;
            Connection conn = Database1.getConnection();
            System.out.println("--------- edit valide ------");
            System.out.println("--------- gaz ------ " + selectedCompagne);
            System.out.println("--------- this ------ " + selectedCompagne.relatedtable);
            System.out.println("--------- this ------ " + this.relatedtable);
            System.out.println("--------- related ------ " + relatedtable);
            System.out.println("--------- fedgerdg  ------ " + idv);
            System.out.println("--------- related ------ " + this.idv);
            CompagneBean.validateBulk(id, conn);
     
        }
    Eric

  6. #6
    Membre du Club
    Femme Profil pro
    Inscrit en
    Mai 2011
    Messages
    177
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Mai 2011
    Messages : 177
    Points : 50
    Points
    50
    Par défaut
    merci infiniment ça marche

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2003] Récupérer le contenu d'une ligne dans un fichier excel (rapidement)
    Par kigrez dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 12/04/2010, 21h20
  2. Réponses: 1
    Dernier message: 10/04/2010, 07h16
  3. Comment récupérer le contenu d'une URL dans une variable ?
    Par Fildz dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 28/08/2006, 09h26
  4. [C#] Recuperer le contenu d'une ligne dans datagrid
    Par thierry2001 dans le forum ASP.NET
    Réponses: 2
    Dernier message: 22/09/2005, 14h56
  5. Réponses: 2
    Dernier message: 07/07/2005, 11h47

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