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ération des valeurs d'un champ dans une liste déroulante


Sujet :

JSF Java

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Janvier 2012
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Janvier 2012
    Messages : 49
    Points : 37
    Points
    37
    Par défaut Récupération des valeurs d'un champ dans une liste déroulante
    Bonsoir;
    J'ai besoin de votre aide.J'ai 2 pages une pour fournisseur (qui contient 3 champs nom , id et prenom) et une page pour facture qui contient une liste deroulante des prenom du fournisseur(qui doivent etre recupérés du champ prenom de la page fournisseur ).voici les deux fichiers xhtml et le bean.

    facture.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
    <?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:composite="http://java.sun.com/jsf/composite">
    <head>
    </head>
    <body>
    <h:form>
    		<h:panelGrid columns="2">
     Id : <h:inputText  value ="#{factureBean.fac.id}"/>
     Date : <h:inputText  value ="#{factureBean.fac.date}"/>
     Fournisseur : <h:selectOneMenu  value ="#{factureBean.fac.list}"/>
     <h:commandButton value="ajouter" action="#{factureBean.ajouter }"/>
     		</h:panelGrid>
    </h:form> 
    </body>
    factureBean:

    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
     
    package com.xxx.facturation.controlleur;
    import javax.annotation.ManagedBean;
    import javax.faces.bean.SessionScoped;
     
    import com.xxx.facturation.dao.FactureDAO;
    import com.xxx.facturation.persistance.Facture;
    import com.xxx.facturation.persistance.Fournisseur;
    @ManagedBean
    @SessionScoped
    public class FactureBean {
     
    	private String list;
    	private Fournisseur f = new  Fournisseur();
    	private Facture fac = new  Facture();
     
    	public Facture getFac() {
    		return fac;
    	}
     
    	public void setFac(Facture fac) {
    		this.fac = fac;
    	}
    	FactureDAO fa= new FactureDAO();
    	public String ajouter(){
    		fa.ajouter(fac);
    		return "Produit ";
    		}
     
    	public Fournisseur getF() {
    		return f;
    	}
     
    	public void setF(Fournisseur f) {
    		this.f = f;
    	}
     
    	public String getList() {
    		return list;
    	}
     
    	public void setList(String list) {
    		list=f.getPrenom();
    		this.list = list;
    	}
     
     
    }
    Merci d'avance.

  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
    salut voici un exemple de recuperation:
    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
     
    @ManagedBean
    @SessionScoped
    public class UserData implements Serializable {
     
    	private static final long serialVersionUID = 1L;
     
    	public String data = "1";
     
    	public String getData() {
    		return data;
    	}
     
    	public void setData(String data) {
    		this.data = data;
    	}
    }
    home.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
     
    <?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:f="http://java.sun.com/jsf/core"    
       xmlns:h="http://java.sun.com/jsf/html">
       <head>
          <title>JSF Tutorial!</title>
       </head>
       <h:body>
          <h2>h::selectOneMenu example</h2>
          <hr />
          <h:form>
             <h3>Combo Box</h3> 
             <h:selectOneMenu value="#{userData.data}">
                <f:selectItem itemValue="1" itemLabel="Item 1" />
                <f:selectItem itemValue="2" itemLabel="Item 2" />
                <f:selectItem itemValue="3" itemLabel="Item 3" />
                <f:selectItem itemValue="4" itemLabel="Item 4" />
                <f:selectItem itemValue="5" itemLabel="Item 5" />				
             </h:selectOneMenu>	
             <h:commandButton value="Submit" action="result" />
          </h:form> 		
       </h:body>
    </html>
    result.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
     
    <?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:f="http://java.sun.com/jsf/core"    
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:ui="http://java.sun.com/jsf/facelets">
       <head>
          <title>JSF Tutorial!</title>
       </head>
       <h:body>
       <h2>Result</h2>
       <hr />
          #{userData.data}
       </h:body>
    </html>
    bonne journée

    Eric

Discussions similaires

  1. [Débutant] Récupération des valeurs d'un champ dans une section extensible
    Par Catarssis dans le forum InfoPath
    Réponses: 16
    Dernier message: 04/09/2012, 10h39
  2. [AC-2000] Récupérer la valeur d'un champs dans une liste ou texte
    Par falco- dans le forum VBA Access
    Réponses: 2
    Dernier message: 29/05/2009, 15h03
  3. Réponses: 7
    Dernier message: 25/01/2009, 22h50
  4. recuperer la valeur du champ dans une liste déroulante
    Par zambudio dans le forum VBA Access
    Réponses: 1
    Dernier message: 26/11/2008, 20h26
  5. Réponses: 1
    Dernier message: 19/03/2006, 20h52

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