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 :

[DataTable] Envoyer les infos d'une ligne d'une dataTable dans une nouvelle page


Sujet :

JSF Java

  1. #1
    Candidat au Club
    Femme Profil pro
    Consultant informatique
    Inscrit en
    Septembre 2012
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Septembre 2012
    Messages : 4
    Points : 3
    Points
    3
    Par défaut [DataTable] Envoyer les infos d'une ligne d'une dataTable dans une nouvelle page
    Bonjour,

    J'ai une page contenant une datatable remplie de "customer" et sous cette datatable, un bouton "Editer". Ma datatable affiche donc le contenu d'une ArrayList dont les éléments sont des customers et j'ai une propriété "selectedCustomer" dans mon backing bean qui représente le customer sélectionné.

    J'ai une autre page qui affiche les informations d'un customer (customerSheet).

    Lorsque je sélectionne une ligne de la datatable (un customer donc), je voudrais pouvoir afficher la customerSheet du customer sélectionné en cliquant sur le bouton "Editer".

    Comment puis-je faire ça simplement?

    Merci d'avance pour vos réponses

  2. #2
    Membre habitué
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2008
    Messages
    179
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Octobre 2008
    Messages : 179
    Points : 172
    Points
    172
    Par défaut
    Bonjour,

    as-tu jeté un œil à la FAQ?
    Roger l'Âne: le lapin devenu grand....
    _______________________________________________________________
    Développeur bio-informatique; spécialiste en rien, généraliste en tout.

    Capitan ! Capitan ! On a aperçu le Loup ! Il a pris d'assaut une chaise à porteurs, à l'aide d'un cul-de-jatte et d'un lapin !
    (Pavillon noir !, Alain Ayroles/Jean-Luc Masboux, éd. Delcourt, coll. Terres de Légendes, 1997, p. 18)

  3. #3
    Candidat au Club
    Femme Profil pro
    Consultant informatique
    Inscrit en
    Septembre 2012
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Septembre 2012
    Messages : 4
    Points : 3
    Points
    3
    Par défaut
    Bonjour Roger_Rabbit,

    Merci pour ta réponse.

    J'ai regardé en effet et j'ai déjà essayé mais ça ne marche pas.
    Est-ce que le fait que je n'ai qu'un seul bouton sous la table (et pas un à chaque ligne) ne pose pas de problème pour l'utilisation du setPropertyActionListener?

  4. #4
    Membre habitué
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2008
    Messages
    179
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Octobre 2008
    Messages : 179
    Points : 172
    Points
    172
    Par défaut
    Il te faut adapter un tout petit peu le principe, mais l'idée est la même.
    Si ton "selectedCustomer" est bien mis à jour dans ton bean au moment de la sélection (première chose à vérifier évidemment), tu pourras le passer en paramétrage de ton action vers ton autre bean.

    De cette façon (non testée, mais l'idée y est):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
        <h:commandButton value="éditer" onComplete="OuvrirMaCustomSheet();">   
          <f:setPropertyActionListener value="#{monPremierBean.selectedCustomer}"
    		target="#{unAutreBean.customer}" />
        </h:commandButton>
    Teste déjà qqchose dans ce genre.
    Roger l'Âne: le lapin devenu grand....
    _______________________________________________________________
    Développeur bio-informatique; spécialiste en rien, généraliste en tout.

    Capitan ! Capitan ! On a aperçu le Loup ! Il a pris d'assaut une chaise à porteurs, à l'aide d'un cul-de-jatte et d'un lapin !
    (Pavillon noir !, Alain Ayroles/Jean-Luc Masboux, éd. Delcourt, coll. Terres de Légendes, 1997, p. 18)

  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
    salut
    envoies nous le code et on pourra avoir de plus amples informations sur ce qui cloche.

  6. #6
    Candidat au Club
    Femme Profil pro
    Consultant informatique
    Inscrit en
    Septembre 2012
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Septembre 2012
    Messages : 4
    Points : 3
    Points
    3
    Par défaut
    Voici le code :

    CustomerList.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>IGNORED</title>
    </h:head>
    <h:body>
    	<ui:composition template="/templates/masterLayout.xhtml">
    		<ui:define name="windowTitle">
                #{msgs.custList_title}
            </ui:define>
     
    		<ui:define name="content">
     
    			<h:form id="form">
     
    				<p:dataTable var="customer" value="#{customerList.customerList}" rowKey="#{customer.id}" 
    					paginator="false" rows="10" selection="#{customerList.selectedCustomer}" selectionMode="single" 
    					filteredValue="#{customerList.filteredCustomers}" id="customerList">   
     
    			        <f:facet name="header">  
    			            Liste des clients 
    			        </f:facet>  
     
    			        <p:column headerText="Référence" sortBy="#{customer.ref}" filterBy="#{customer.ref}" id="ref">  
    			            #{customer.ref}  
    			        </p:column>  
     
    			        <p:column headerText="Nom" sortBy="#{customer.name}" filterBy="#{customer.name}" id="name">  
    			            #{customer.name}  
    			        </p:column>  
     
    			        <p:column headerText="Adresse" sortBy="#{customer.address}" filterBy="#{customer.address}" id="address">  
    			            #{customer.address}  
    			        </p:column>  
     
    			        <p:column headerText="Téléphone" sortBy="#{customer.phone}" filterBy="#{customer.phone}" id="phone">  
    			            #{customer.phone}"  
    			        </p:column> 
     
    			        <f:facet name="footer">  
    			            <p:commandButton id="viewButton" value="View" icon="ui-icon-search"  
    			                    update=":form:display" oncomplete="customerDialog.show()"/>  
    			        </f:facet>  
     
    			    </p:dataTable> 
     
    			    <p:dialog header="Aperçu client" widgetVar="customerDialog" resizable="false"
                  		width="300" showEffect="slide" hideEffect="slide">
     
    			        <h:panelGrid id="display" columns="2" cellpadding="4">
     
    			            <h:outputText value="Référence:" />
    			            <h:outputText value="#{customerList.selectedCustomer.ref}" id="ref"/>
     
    			            <h:outputText value="Nom:" />
    			            <h:outputText value="#{customerList.selectedCustomer.name}" id="name"/>
     
    			            <h:outputText value="Adresse" />
    			            <h:outputText value="#{customerList.selectedCustomer.address}" id="address"/>
     
    			            <h:outputText value="Phone:" />
    			            <h:outputText value="#{customerList.selectedCustomer.phone}" id="phone"/>
     
    			            <h:outputText value="Gsm" />
    			            <h:outputText value="#{customerList.selectedCustomer.gsm}" id="gsm"/>
     
    			            <h:outputText value="Email:" />
    			            <h:outputText value="#{customerList.selectedCustomer.email}" id="email"/>
     
    			            <h:outputText value="TVA:" />
    			            <h:outputText value="#{customerList.selectedCustomer.tva}" id="tva"/>
     
    			        </h:panelGrid>
    			    </p:dialog> 
     
    				<p:commandButton value="éditer" onComplete="#{customerList.openCustomer()}">   
    				      <f:setPropertyActionListener value="#{customerList.selectedCustomer}"
    						target="#{customer}" />
    			    </p:commandButton>
     
    			</h:form>
    		</ui:define>
    	</ui:composition>
    </h:body>
    </html>
    CustomerSheet.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
     
    <?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>IGNORED</title>
    </h:head>
    <h:body>
    	<ui:composition template="/templates/masterLayout.xhtml">
    		<ui:define name="windowTitle">
    	            #{msgs.custList_title}
    	    </ui:define>
     
    		<ui:define name="content">
     
    			<h:form id="form">
    				<p:panel id="display" header="Information" style="margin-top:10px;">
    					<h:panelGrid columns="2">
    						<h:outputText value="Référence: " />
    						<h:outputText value="#{customer.ref}" />
     
    						<h:outputText value="Nom: " />
    						<h:outputText value="#{customer.name}" />
     
    						<h:outputText value="Adresse: " />
    						<h:outputText value="#{customer.address}" />
     
    						<h:outputText value="Téléphone: " />
    						<h:outputText value="#{customer.phone}" />
     
    						<h:outputText value="GSM: " />
    						<h:outputText value="#{customer.gsm}" />
     
    						<h:outputText value="Email: " />
    						<h:outputText value="#{customer.email}" />
     
    						<h:outputText value="TVA: " />
    						<h:outputText value="#{customer.tva}" />
    					</h:panelGrid>
    				</p:panel>
     
    			</h:form>
    		</ui:define>
    	</ui:composition>
    </h:body>
    </html>
    CustomerList.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
     
    public class CustomerList {
    	private List<Customer> customerList = new ArrayList<Customer>();
     
    	private List<Customer> filteredCustomers;
     
    	private Customer selectedCustomer;
     
    	/**
             * Constructor.
             */
    	public CustomerList() {
    		this.getAllCustomer();
    	}
     
     
    	/* ********** MANAGERS ********** */
     
    	public String getAllCustomer() {
    		Connection connection = ConnectionManager.getConnection();
     
    		CustomerDAO customerDAO = new CustomerDAO(connection);
    		boolean success = customerDAO.findAll(customerList);
     
    		ConnectionManager.closeConnection(connection);
     
    		return Processings.booleanProcessing(success);
    	}
     
    	public String openCustomer() {
     
    		return "success";
    	}
     
    	public Customer getSelectedCustomer() {
    		return selectedCustomer;
    	}
     
    	public void setSelectedCustomer(Customer selectedCar) {
    		this.selectedCustomer = selectedCar;
    	}
     
    	public List<Customer> getFilteredCustomers() {  
            return filteredCustomers;  
        }  
     
        public void setFilteredCustomers(List<Customer> filteredCustomers) {  
            this.filteredCustomers = filteredCustomers;  
        }  
     
    	/* ********** GETTERS ********** */
     
    	public List<Customer> getCustomerList() {
    		return customerList;
    	}
     
    	/* ********** SETTERS ********** */
     
    	public void setCustomerList(List<Customer> customerList) {
    		this.customerList = customerList;
    	}
    }
    Customer.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
     
    public class Customer implements Serializable {
    	// customer id into the database
    	private int id;
    	// customer reference used by managers
    	private String ref;
     
    	private String name;
    	private String address;
     
    	private String phone;
    	private String gsm;
    	private String email;
     
    	private String tva;
     
    	private List<Order> orderList;
     
    	private boolean archived;
     
    	/**
             * Empty constructor.
             */
    	public Customer() {
    		// nothing to do
    	}
     
    	/* ********** GETTERS ********** */
     
    	public int getId() {
    		return id;
    	}
     
    	public String getRef() {
    		return ref;
    	}
     
    	public String getName() {
    		return name;
    	}
     
    	public String getAddress() {
    		return address;
    	}
     
    	public String getPhone() {
    		return phone;
    	}
     
    	public String getGsm() {
    		return gsm;
    	}
     
    	public String getEmail() {
    		return email;
    	}
     
    	public String getTva() {
    		return tva;
    	}
     
    	public List<Order> getOrderList() {
    		return orderList;
    	}
     
    	public Order getOrderList(int index) {
    		return orderList.get(index);
    	}
     
    	public boolean getArchived() {
    		return archived;
    	}
     
    	/* ********** SETTERS ********** */
     
    	public void setId(int id) {
    		this.id = id;
    	}
     
    	public void setRef(String ref) {
    		this.ref = ref;
    	}
     
    	public void setName(String name) {
    		this.name = name;
    	}
     
    	public void setAddress(String address) {
    		this.address = address;
    	}
     
    	public void setPhone(String phone) {
    		this.phone = phone;
    	}
     
    	public void setGsm(String gsm) {
    		this.gsm = gsm;
    	}
     
    	public void setEmail(String email) {
    		this.email = email;
    	}
     
    	public void setTva(String tva) {
    		this.tva = tva;
    	}
     
    	public void setOrderList(List<Order> orderList) {
    		this.orderList = orderList;
    	}
     
    	public void setOrderList(int index, Order order) {
    		orderList.add(index, order);
    	}
     
    	public void setArchived(boolean archived) {
    		this.archived = archived;
    	}
    }
    faces-config.xml
    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
    <?xml version="1.0"?>
    <faces-config xmlns="http://java.sun.com/xml/ns/javaee" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
          http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
       version="2.0">
       <application>
          <locale-config>
             <default-locale>fr</default-locale>
             <supported-locale>en</supported-locale>
          </locale-config>
          <resource-bundle>
             <base-name>com.almach.messages</base-name>
             <var>msgs</var>
          </resource-bundle>
       </application>
     
       <managed-bean>
           <managed-bean-name>customer</managed-bean-name>
           <managed-bean-class>com.almach.beans.Customer</managed-bean-class>
           <managed-bean-scope>request</managed-bean-scope>
       </managed-bean>
       <managed-bean>
           <managed-bean-name>customerList</managed-bean-name>
           <managed-bean-class>com.almach.beans.CustomerList</managed-bean-class>
           <managed-bean-scope>session</managed-bean-scope>
       </managed-bean>
     
        <navigation-rule>
           <from-view-id>/pages/customerList.xhtml</from-view-id>
           <navigation-case>
               <from-outcome>success</from-outcome>
               <to-view-id>/pages/customerSheet.xhtml</to-view-id>
           </navigation-case>
       </navigation-rule>
     
    </faces-config>
    Merci

  7. #7
    Candidat au Club
    Femme Profil pro
    Consultant informatique
    Inscrit en
    Septembre 2012
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Septembre 2012
    Messages : 4
    Points : 3
    Points
    3
    Par défaut
    Bonjour,

    J'ai finalement trouvé ce qui clochait

    Dans mon bean "CustomerList", je n'avais pas injecté correctement mon bean "Customer". Il manquait la ligne ci-dessous :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    @ManagedProperty(value="#{customer}")
    Maintenant ça fonctionne avec la solution du "setPropertyActionListener" proposée par Roger_Rabbit.

    Merci à vous.

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

Discussions similaires

  1. Réponses: 9
    Dernier message: 05/11/2012, 15h28
  2. Réponses: 2
    Dernier message: 24/03/2008, 11h35
  3. Réponses: 2
    Dernier message: 30/01/2008, 22h40
  4. Réponses: 0
    Dernier message: 06/12/2007, 11h08
  5. copier une ligne et la coller dans une nouvelle
    Par alexkickstand dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 06/09/2007, 20h10

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