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 la ligne sélectionnée dans ScrollableDataTable


Sujet :

JSF Java

  1. #1
    Membre éprouvé
    Inscrit en
    Mars 2008
    Messages
    1 123
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 1 123
    Par défaut Récupérer la ligne sélectionnée dans ScrollableDataTable
    Bonsoir à tous

    voici mon bean qui me remplit un scrolldatatable
    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
     
    package Test;
     
     
     import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Vector;
     
    import javax.faces.component.UIComponent;
    import javax.faces.component.html.HtmlDataTable;
    import javax.faces.context.FacesContext;
    import javax.faces.event.ActionEvent;
    import javax.faces.model.DataModel;
    import javax.faces.model.SelectItem;
     
    import org.richfaces.model.impl.ListDataModel;
     
    import Test.BDD;
     
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
    import java.sql.Connection;
     
     
    public class Recherche {
    	private String MO;  
    	private DataModel list = new ListDataModel();
        //private ArrayList<EMPLOYES> list;
    	private ResultSet  RS;
     
    	public String getMO() {
    		return MO;
    	}
    	public void setMO(String MO) {
    		this.MO = MO;
    	}
     
    	@SuppressWarnings("unchecked")
     
      public DataModel getlist() {
     
            if (list == null) {
     
     
     
     
                   Connection con = new BDD().getCon();
     
    				try {
    					//list = new ArrayList<EMPLOYES>(); 
    					 String SqlStr = "  select   CODE_SOC, MATRI, NOM, PRENOM, FONCTION as LIBEL,'EXTERNE' as TYPE   from DC_DEMANDEUREX  ";//WHERE UPPER(DC_DEMANDEUREX.NOM) LIKE '%"+ MO.toUpperCase() +"%' OR UPPER(DC_DEMANDEUREX.PRENOM) LIKE '%"+ MO.toUpperCase() +"%'UNION" ; 
    					// SqlStr =SqlStr+ "  select   CODE_SOC, MATRI, NOM, PRENOM, LIBEL,'INTERNE' as INTERNE from DC_EMPLOYES WHERE UPPER(DC_EMPLOYES.NOM) LIKE '%"+ MO.toUpperCase() +"%'OR UPPER(DC_EMPLOYES.PRENOM) LIKE '%"+ MO.toUpperCase() +"%' ORDER BY  TYPE DESC, CODE_SOC, MATRI, NOM, PRENOM ";  
    					 Statement stmt= con.createStatement();
    					 RS = stmt.executeQuery(SqlStr);
     
    						while(RS.next())
    						{
    							 list.setWrappedData( new EMPLOYES(RS.getString("CODE_SOC"),RS.getInt("MATRI"),RS.getString("NOM"),RS.getString("PRENOM"),RS.getString("LIBEL"),RS.getString("TYPE") ));
    						}
    				} catch (SQLException e) {
     
    					e.printStackTrace();
    				}
     
     
               }
               return list;
       }
     
     
    	public void selectionneElement(ActionEvent evt) {
    	    // On récupère la datatable.
    	    HtmlDataTable table = getParentDatatable((UIComponent) evt.getSource());
    	    // On récupère l'objet affiché à la bonne ligne de la datatable.
    	    Object o = table.getRowData();
    	    // On récupère aussi son index
    	    int index = table.getRowIndex();
    	    // Suite du traitement sur l'objet sélectionné.
    	}
     
    	private HtmlDataTable getParentDatatable(UIComponent compo) {
    	    if (compo == null) {
    	        return null;
    	    }
    	    if (compo instanceof HtmlDataTable) {
    	        return (HtmlDataTable) compo;
    	    }
    	    return getParentDatatable(compo.getParent());
    	}
     
     
     
     
     
    }

    et le code de ma table
    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
     
    <rich:scrollableDataTable  var="RECH" value="#{Recherche.list}" 
     frozenColCount="1"
                first="0"
                rows="40" 
                width="680px"
                height="396px" style="font-size:12pt;">
     
                 <rich:column sortBy="#{RECH.TYPE}"  width="80px" style="text-align:center;font-size:12pt;" >
                  <f:facet name="header"><h:outputText value="TYPE" /></f:facet>
                  <h:outputText  value="#{RECH.TYPE}"style="text-align:center;" />
                 </rich:column> 
     
               <rich:column sortBy="#{RECH.MATRI}"  width="70px" style="text-align:center;font-size:12pt;">
                 <f:facet name="header"><h:outputText value="MATRICULE" /></f:facet>
                 <h:outputText value="#{RECH.MATRI}" style="text-align:center;"/>
                </rich:column>
     
                  <rich:column sortBy="#{RECH.CODE_SOC}"  width="80px" style="text-align:center;font-size:12pt;">
                 <f:facet name="header"><h:outputText value="CODE SOCIETE" /></f:facet>
                 <h:outputText value="#{RECH.CODE_SOC}" style="text-align:center;"/>
                </rich:column>
     
     
                <rich:column sortBy="#{RECH.NOM}"  width="100px" style="text-align:center;font-size:12pt;">
                 <f:facet name="header"><h:outputText value="NOM" /></f:facet>
                 <h:outputText value="#{RECH.NOM}" style="text-align:center;"/>
                </rich:column>
     
                 <rich:column sortBy="#{RECH.PRENOM}"  width="100px" style="text-align:center;font-size:12pt;">
                  <f:facet name="header"><h:outputText value="PRENOM" /></f:facet>
                  <h:outputText  value="#{RECH.PRENOM}"style="text-align:center;" />
                 </rich:column>
     
                 <rich:column sortBy="#{RECH.LIBEL}"  width="250px" style="text-align:center;font-size:12pt;">
                  <f:facet name="header"><h:outputText value="FONCTION" /></f:facet>
                  <h:outputText  value="#{RECH.LIBEL}"style="text-align:center;" />
                 </rich:column>
     
     
     
     
    </rich:scrollableDataTable >
    comment je peux modifier mes codes pour que:
    quad je clique sur un COmmandButton j'aurai le contenu d'une cellule de la ligne sélectionnée

    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 : 47
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Java craftsman
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2005
    Messages : 3 790
    Par défaut
    Si ton bouton se trouve dans la table, il te suffit d'appliquer l'une des 3 solutions proposées dans la FAQ JSF de DVP...
    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 éprouvé
    Inscrit en
    Mars 2008
    Messages
    1 123
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 1 123
    Par défaut
    merci beaucoup,
    J'ai créer une Popup qui contient une table
    au dessous un bouton qui me valide la sélection pour envoyer le contenu de la premiere colonne de la lgne sélectionnée à ma page mére
    j'essaye de le faire plus de 5 jours et je n'arrive pas à le réaliser

  4. #4
    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 : 47
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Java craftsman
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2005
    Messages : 3 790
    Par défaut
    On peut voir toute ta page jsf ?
    Comment se fait la sélection ? D'après le code, il n'y a que des textes, aucun champ de saisie...
    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

  5. #5
    Membre éprouvé
    Inscrit en
    Mars 2008
    Messages
    1 123
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 1 123
    Par défaut
    Voici le code de ma page 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
    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
     
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
     <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
     
     
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <f:view>
    <html>
     
     
    <head>
     
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Gestion </title>
    <meta http-equiv="refresh" content="100">
    <script language='javascript'> 
     
     
     
    function RechNom() {
    	Richfaces.showModalPanel('panel');
    	}
     
    </script> 
    </head>
    <body   link="#FFFFFF" ALINK="#FFFFFF" >
    <table   border="1" cellpadding="0" cellspacing="0" style="  border-collapse: collapse" bordercolor="#FF9933" width="1133" height="628">
     
     
     
     
    <tr valign="top" >
     
     
     
     
     
     
     
     
        <td width="898" height="579" bordercolor="#FF9933" bgcolor="#FFFFFF"  valign="top" style=" width : 723px;">
     
     
     
     
     
     
    <rich:tabPanel id="Article" height ="579" width="898" style=" height : 497px;">
    <rich:tab name="NA" label="Nouvel article" >
     
                     <h:form id="NouvelArticle">        
                              <table border="0" width="85%" cellspacing="2" cellpadding="4"  style=" fontstyle:bold;"> 
     
     
     
     
     
     
     
     
              <tr> 
                <td width="289" align="left"><font face="Calibri"size="4" ><b>
    			<label id="af">Affect&eacute; &agrave;:</label>
    			</b></font></td> 
     
    			 <td width="50%">
    			 <h:inputText styleClass="inputText" id="Affect" size="75"  style=" width : 403px;" disabled="true"/>
     
    			 </td> 
     
    			 <td style=" width : 147;" align ="right"> 
     
    			 <a4j:commandButton value="Recherche" onclick="javascript:RechNom()" />
     
    			 </td> 
              </tr>  
     
              <tr style=" height : 31px;">
              <td></td>
              <td valign="top"></td>
     
              </tr>
              <tr> 
                <td width="70%" valign="top"><font face="Calibri" size="4"><b></b></font></td> 
                 <td width="50%"> </td> 
              </tr>
     
              <tr> 
                <td width="142">&nbsp;</td> 
                <td width="405" align="right">
     
                 </td> 
              </tr> 
     
     
            </table>
     
       <rich:modalPanel id="panel" width="700" height="498">
            <f:facet name="header">
                <h:panelGroup>
                    <h:outputText value="Sélection demandeur"></h:outputText>
                </h:panelGroup>
            </f:facet>
            <f:facet name="controls">
                <h:panelGroup>
                 <rich:componentControl for="panel" attachTo="hidelink" operation="hide" event="onclick"/>
                </h:panelGroup>
            </f:facet>
     
       <table border="0" cellpadding="0" cellspacing="0" style="border-collapse:
     collapse; width : 821;" height="467">
       <colgroup>
         <col width="120" style="width: 90pt"><col width="80" style="width: 60pt">
         <col width="169" style="width: 127pt"><col width="108" style="width: 81pt">
       </colgroup>
       <tr height="257" style="height: 192.75pt" valign="top">
       <td colspan="4" height="355" style="border-top:1px solid #FFCC66; text-align: cleft; vertical-align: top; color: #000000; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; white-space: nowrap; border-left: 1px solid #FFCC66; border-right: 1px solid #FFCC66; padding-left: 1px; padding-right: 1px; padding-top: 1px; border-bottom-width:medium" width="248">
     
     
     
     
     <a4j:commandButton value="Show Current Selection" reRender="table" 
     
                    oncomplete="javascript:Richfaces.showModalPanel('panel');"/>
     
     
    <rich:scrollableDataTable  var="RECH" value="#{Recherche.list}" 
     frozenColCount="1"
                first="0"
                rows="40" 
                width="680px"
                height="396px" style="font-size:12pt;">
     
                 <rich:column sortBy="#{RECH.TYPE}"  width="80px" style="text-align:center;font-size:12pt;" >
                  <f:facet name="header"><h:outputText value="TYPE" /></f:facet>
                  <h:outputText  value="#{RECH.TYPE}"style="text-align:center;" />
                 </rich:column> 
     
               <rich:column sortBy="#{RECH.MATRI}"  width="70px" style="text-align:center;font-size:12pt;">
                 <f:facet name="header"><h:outputText value="MATRICULE" /></f:facet>
                 <h:outputText value="#{RECH.MATRI}" style="text-align:center;"/>
                </rich:column>
     
                  <rich:column sortBy="#{RECH.CODE_SOC}"  width="80px" style="text-align:center;font-size:12pt;">
                 <f:facet name="header"><h:outputText value="CODE SOCIETE" /></f:facet>
                 <h:outputText value="#{RECH.CODE_SOC}" style="text-align:center;"/>
                </rich:column>
     
     
                <rich:column sortBy="#{RECH.NOM}"  width="100px" style="text-align:center;font-size:12pt;">
                 <f:facet name="header"><h:outputText value="NOM" /></f:facet>
                 <h:outputText value="#{RECH.NOM}" style="text-align:center;"/>
                </rich:column>
     
                 <rich:column sortBy="#{RECH.PRENOM}"  width="100px" style="text-align:center;font-size:12pt;">
                  <f:facet name="header"><h:outputText value="PRENOM" /></f:facet>
                  <h:outputText  value="#{RECH.PRENOM}"style="text-align:center;" />
                 </rich:column>
     
                 <rich:column sortBy="#{RECH.LIBEL}"  width="250px" style="text-align:center;font-size:12pt;">
                  <f:facet name="header"><h:outputText value="FONCTION" /></f:facet>
                  <h:outputText  value="#{RECH.LIBEL}"style="text-align:center;" />
                 </rich:column>
     
     
     
     
    </rich:scrollableDataTable >
     
     
     
    </td>
       </tr>
       <tr height="8" style="height: 6.0pt">
         <td height="19" style="border-left:1px solid #FFCC66; vertical-align: middle; color: #000000; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; padding-left: 1px; padding-right: 1px; padding-top: 1px" width="163">
         </td>
         <td style="vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px" height="19" width="80">&nbsp;</td>
         <td style="vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px" width="446" height="19">&nbsp;</td>
         <td style="vertical-align: middle; color: #000000; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border-right: 1px solid #FFCC66; padding-left: 1px; padding-right: 1px; padding-top: 1px; border-left-width:medium; border-top-width:medium; border-bottom-width:medium" width="135" height="19">
         &nbsp;</td>
       </tr>
       <tr height="38" style="height: 28.5pt">
         <td height="36" style="vertical-align: middle; color: #000000; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; white-space: nowrap; border-left: 1px solid #FFCC66; border-top: 1px solid #FFCC66; border-bottom: 1px solid #FFCC66; padding-left: 1px; padding-right: 1px; padding-top: 1px; border-right-width:medium" width="110">
         <a4j:commandButton style=" width : 96px; float:left" value="Fermer" onclick="javascript:Richfaces.hideModalPanel('panel');" />
     
         </td>
         <td colspan="2" height="36" style="vertical-align: middle; color: #000000; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; white-space: nowrap; border-top: 1px solid #FFCC66; border-bottom: 1px solid #FFCC66; padding-left: 1px; padding-right: 1px; padding-top: 1px; border-right-width:medium" width="297">
         &nbsp;</td>
         <td style="vertical-align: middle; color: #000000; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border-right: 1px solid #FFCC66; border-top: 1px solid #FFCC66; border-bottom: 1px solid #FFCC66; padding-left: 1px; padding-right: 1px; padding-top: 1px; " width="135" height="36">
         <h:commandButton   style=" width : 96px; float:right" value="Valider" id="Rech3" />
         </td>
       </tr>
     </table>
     
     
     
     
     
        </rich:modalPanel>
     
     
            </h:form>
     
    </rich:tab>                    
     
     
    </rich:tabPanel>
     
     
     
     
     </td>
     
     
    </table>
    </body>
    </html>
    </f:view>

  6. #6
    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 : 47
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Java craftsman
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2005
    Messages : 3 790
    Par défaut
    En fait le composant scrollableDataTable propose un attribut selection qui te permet, du côté de ton serveur, de connaitre la sélection faite par l'utilisateur. Tu peux trouver sur la page de documentation de ce composant (ici) un exemple d'utilisation de cet attribut (chapitre 6.6.14.3).
    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

  7. #7
    Membre éprouvé
    Inscrit en
    Mars 2008
    Messages
    1 123
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 1 123
    Par défaut
    Merci mais pour le getSelection et le setSelection
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
     
    public SimpleSelection getSelection() {
    	    return selection;
    	    }
     
    	    public void setSelection(SimpleSelection selection) {
    	    this.selection = selection;
    	    }
    le selection c'est la ligne sélectionnée????
    si oui comment je peux avoir le contenu d'une cellule de cette ligne
    Merci

  8. #8
    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 : 47
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Java craftsman
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2005
    Messages : 3 790
    Par défaut
    En fait ça te donne un élément (ou plusieurs, dans le cas d'une sélection multiple) de ta liste, sur laquelle itère ton tableau. Dans ton cas, il s'agira d'un élément de type EMPLOYES (le nom de ta classe ne respecte pas les conventions Java soit dit en passant).

    Il te suffira alors d'appeler le bon getter sur cet objet, pour obtenir l'info que tu souhaites...
    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

  9. #9
    Membre éprouvé
    Inscrit en
    Mars 2008
    Messages
    1 123
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 1 123
    Par défaut
    J'ai modifier mon 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
    104
    105
    106
     
    package Test;
     
     
     import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Vector;
     
    import javax.faces.model.SelectItem;
     
    import org.richfaces.model.ScrollableTableDataModel.SimpleRowKey;
    import org.richfaces.model.selection.Selection;
    import org.richfaces.model.selection.SimpleSelection;
     
    import Test.BDD;
     
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
    import java.sql.Connection;
     
     
    public class Recherche {
    	private String maValeur;  
    	private SimpleSelection selection;
    	private ArrayList<EMPLOYES> list, List1;
    	private ResultSet  RS;
    	private EMPLOYES selectEM;
     
     
     
    	@SuppressWarnings("unchecked")
     
      public ArrayList<EMPLOYES> getlist() {
     
            if (list == null) {
     
     
                   Connection con = new BDD().getCon();
     
    				try {
    					 list = new ArrayList<EMPLOYES>(); 
    					 String SqlStr = "  select   CODE_SOC, MATRI, NOM, PRENOM, FONCTION as LIBEL,'EXTERNE' as TYPE   from  DC_DEMANDEUREX";// UNION" ; 
    					// SqlStr =SqlStr+ "  select   CODE_SOC, MATRI, NOM, PRENOM, LIBEL,'INTERNE' as INTERNE from DC_EMPLOYES ORDER BY  TYPE DESC, CODE_SOC, MATRI, NOM, PRENOM ";  
    					 Statement stmt= con.createStatement();
    					 RS = stmt.executeQuery(SqlStr);
     
    						while(RS.next())
    						{
    							 list.add( new EMPLOYES(RS.getString("CODE_SOC"),RS.getInt("MATRI"),RS.getString("NOM"),RS.getString("PRENOM"),RS.getString("LIBEL"),RS.getString("TYPE") ));
    						}
     
    				} catch (SQLException e) {
     
    					e.printStackTrace();
    				}
     
     
               }
     
               return list;
       }
     
     
    	  public SimpleSelection getSelection() 
    	  {
    		 return selection;
    	  }
    	  public void setSelection(SimpleSelection selection) 
    	  {
    		 this .selection = selection;
    	  }
     
    	  public String takeSelection() 
    	  {
    		getSelectedEM().clear();
    		Iterator<Object> iterator = getSelection().getKeys();
    		while (iterator.hasNext()) 
    		{
    		 SimpleRowKey key = (SimpleRowKey) iterator.next();
    		 getSelectedEM().add(getlist().get(key.intValue()));
    		}
    		  return null;
    	  }
     
    	  public ArrayList<EMPLOYES> getSelectedEM() 
    	  {
    		return list;
    	  }
     
    	  public void setSelectedEM(
    		 ArrayList<EMPLOYES> list) 
    	  {
     
    		this.list = list;
    	   }
     
     
     
    }
    pour mon 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
     
     
    <a4j:commandButton value="Show Current Selection" reRender="table" 
                            action="#{Recherche.takeSelection}"  
                            oncomplete="javascript:Richfaces.showModalPanel('panel');"/>
    <rich:scrollableDataTable selection="#{Recherche.selection}"  var="RECH" value="#{Recherche.list}" 
     frozenColCount="1"
                first="0"
                rows="40" 
                width="680px"
                height="396px" style="font-size:12pt;">
     
                 <rich:column width="80px" style="text-align:center;font-size:12pt;" >
                  <f:facet name="header"><h:outputText value="TYPE" /></f:facet>
                  <h:outputText  value="#{RECH.TYPE}"style="text-align:center;" />
                 </rich:column> 
     
               <rich:column width="70px" style="text-align:center;font-size:12pt;">
                 <f:facet name="header"><h:outputText value="MATRICULE" /></f:facet>
                 <h:outputText value="#{RECH.MATRI}" style="text-align:center;"/>
                </rich:column>
     
                  <rich:column width="80px" style="text-align:center;font-size:12pt;">
                 <f:facet name="header"><h:outputText value="CODE SOCIETE" /></f:facet>
                 <h:outputText value="#{RECH.CODE_SOC}" style="text-align:center;"/>
                </rich:column>
     
     
                <rich:column width="100px" style="text-align:center;font-size:12pt;">
                 <f:facet name="header"><h:outputText value="NOM" /></f:facet>
                 <h:outputText value="#{RECH.NOM}" style="text-align:center;"/>
                </rich:column>
     
                 <rich:column width="100px" style="text-align:center;font-size:12pt;">
                  <f:facet name="header"><h:outputText value="PRENOM" /></f:facet>
                  <h:outputText  value="#{RECH.PRENOM}"style="text-align:center;" />
                 </rich:column>
     
                 <rich:column width="250px" style="text-align:center;font-size:12pt;">
                  <f:facet name="header"><h:outputText value="FONCTION" /></f:facet>
                  <h:outputText  value="#{RECH.LIBEL}"style="text-align:center;" />
                 </rich:column>
     
     
     
     
    </rich:scrollableDataTable >
    je n'arrive pas à affecter la valeur de la premier cellule de la ligne sélectionner à mon inputtext

  10. #10
    Membre éprouvé
    Inscrit en
    Mars 2008
    Messages
    1 123
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 1 123
    Par défaut
    pour le input j'ai lui affecté la valeur comme suit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <h:inputText styleClass="inputText" value="#{Recherche.selected}"id="Affect" size="75"  style=" width : 403px;" disabled="true"/>
    et j'ai modifier mon bean comme suit:
    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
     
    package Test;
     
     
     import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Vector;
     
    import javax.faces.component.UIComponent;
    import javax.faces.component.UIData;
    import javax.faces.context.FacesContext;
    import javax.faces.event.AbortProcessingException;
    import javax.faces.event.ActionEvent;
    import javax.faces.model.SelectItem;
     
    import org.richfaces.component.UIScrollableDataTable;
    import org.richfaces.model.ScrollableTableDataModel.SimpleRowKey;
    import org.richfaces.model.selection.Selection;
    import org.richfaces.model.selection.SimpleSelection;
     
    import Test.BDD;
     
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
    import java.sql.Connection;
     
     
    public class Recherche {
    	private SimpleSelection selection = new SimpleSelection();
    	private static List<EMPLOYES> list = null;
    	private ArrayList<EMPLOYES> SelectedEM= new ArrayList<EMPLOYES>();
    	private ResultSet  RS;
    	private UIScrollableDataTable table;
     
    	private int Selected;
     
     
     
    	@SuppressWarnings("unchecked")
     
      public List<EMPLOYES> getlist() {
     
            if (list == null) {
     
     
                   Connection con = new BDD().getCon();
     
    				try {
    					 list = new ArrayList<EMPLOYES>(); 
    					 String SqlStr = "  select   CODE_SOC, MATRI, NOM, PRENOM, FONCTION as LIBEL,'EXTERNE' as TYPE   from  DC_DEMANDEUREX";// UNION" ; 
    					// SqlStr =SqlStr+ "  select   CODE_SOC, MATRI, NOM, PRENOM, LIBEL,'INTERNE' as INTERNE from DC_EMPLOYES ORDER BY  TYPE DESC, CODE_SOC, MATRI, NOM, PRENOM ";  
    					 Statement stmt= con.createStatement();
    					 RS = stmt.executeQuery(SqlStr);
     
    						while(RS.next())
    						{
    							 list.add( new EMPLOYES(RS.getString("CODE_SOC"),RS.getInt("MATRI"),RS.getString("NOM"),RS.getString("PRENOM"),RS.getString("LIBEL"),RS.getString("TYPE") ));
     
    						}
     
    				} catch (SQLException e) {
     
    					e.printStackTrace();
    				}
     
     
               }
     
     
     
     
               return  list;
       }
     
     
    	public SimpleSelection getSelection() 
    	{
            return selection;
        }
     
        public void setSelection(SimpleSelection selection)
        {
            this .selection = selection;
        }
     
     
    	//******************************************** 
     
    	 public int getSelected() 
    	  {
    		  if (SelectedEM != null)
    		  {
    			//Affecter la valeur de la première cellule
    		  }
     
    		return Selected;
    	  }
     
     
     
     
     
    	 public String takeSelection() {
    			getSelectedEM().clear();
    			if (getSelection().isSelectAll()){
    				getSelectedEM().addAll(list);
    			}else{
    				Iterator<Object> iterator = getSelection().getKeys();
    				while (iterator.hasNext()){
    					Object key = iterator.next();
    					table.setRowKey(key);
    					getSelectedEM().add((EMPLOYES)table.getRowData());
     
     
    				}
    			}
    			return null;
    		}
     
     
    	  //******************************************
    	    public ArrayList<EMPLOYES> getSelectedEM() {
    	        return SelectedEM;
    	    }
     
    	    public void setSelectedEM( ArrayList<EMPLOYES> SelectedEM) 
    	    {
    	        this.SelectedEM = SelectedEM;
     
    	    }
    }
    et le code de mon bouton qui envoie la sélection à mon Input :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    <a4j:commandButton value="Show Current Selection" reRender="Affect" 
    action="#{Recherche.takeSelection}" immediate="true"/>
    quand j'ai ajouté un system.out.print à la fin de takeselection rien ne s'affiche
    j'ai remarqué que la méthode n'est jamais appelée

    où est le problème dans mon code

  11. #11
    Membre éprouvé
    Inscrit en
    Mars 2008
    Messages
    1 123
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 1 123
    Par défaut
    SVP, où est le problème j'ai toujour la taille de ma sélection = 0

    pourquoi

  12. #12
    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 : 47
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Java craftsman
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2005
    Messages : 3 790
    Par défaut
    Supprime le immediate="true" de ton bouton.

    Sinon, es-tu passé en mode de débug, pour voir ce qui se passe dans ton fonction takeSelection ?
    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

  13. #13
    Membre éprouvé
    Inscrit en
    Mars 2008
    Messages
    1 123
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 1 123
    Par défaut
    Merci à vous
    mais pour récupérer la valeur de la premiere cellule dans mon inputtext
    je n'ai pas pu le faire

    j'ai l'erreur suivante quand je clique sur mon bouton
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    javax.servlet.ServletException: #{Recherche.takeSelection}: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    SVP je suis complétement bloquée

  14. #14
    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 : 47
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Java craftsman
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2005
    Messages : 3 790
    Par défaut
    As-tu supprimé le immediate="true" de ton bouton ?

    Es-tu passé en mode de débug, pour voir ce qui se passe dans ton fonction takeSelection ?
    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

  15. #15
    Membre éprouvé
    Inscrit en
    Mars 2008
    Messages
    1 123
    Détails du profil
    Informations forums :
    Inscription : Mars 2008
    Messages : 1 123
    Par défaut
    OUi, j'ai fait tout ça
    il rentre dans takeselection mais pas dans cette boucle
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    while (iterator.hasNext()) 
    		{
    		 SimpleRowKey key = (SimpleRowKey) iterator.next();
    		 getSelectedEM().add(getlist().get(key.intValue()));
    		}

Discussions similaires

  1. récupérer la ligne sélectionnée dans un GtkListStore
    Par katorps dans le forum GTK+ avec C & C++
    Réponses: 4
    Dernier message: 29/08/2012, 23h16
  2. Récupérer la ligne sélectionnée dans un ListView
    Par altropus dans le forum Windows Presentation Foundation
    Réponses: 8
    Dernier message: 15/02/2010, 11h57
  3. Réponses: 3
    Dernier message: 16/07/2008, 11h01
  4. Récupérer le numéro de la ligne sélectionnée dans une variable?
    Par drthodt dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 15/10/2007, 11h48
  5. Récupérer la ligne sélectionnée dans un ListBox
    Par jmjmjm dans le forum Composants VCL
    Réponses: 3
    Dernier message: 11/11/2005, 22h13

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