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

Développement Web en Java Discussion :

Ajout d'un bouton « + » à droite d'un champ texte qui fait apparaître 3 champs dynamiquement


Sujet :

Développement Web en Java

  1. #1
    Membre à l'essai
    Homme Profil pro
    Développeur Java
    Inscrit en
    Juin 2013
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2013
    Messages : 8
    Points : 11
    Points
    11
    Par défaut Ajout d'un bouton « + » à droite d'un champ texte qui fait apparaître 3 champs dynamiquement
    Bonjour,

    Je souhaite ajouter un bouton « + » à droite d'un champ texte comme dans l'image ci dessous (le résultat souhaité):
    Mais j'ai un problème au niveau du bouton (+) de deuxième champs qui n'affiche pas le troisième champs..est ce que vous avez une idée
    Nom : champs.jpg
Affichages : 116
Taille : 13,2 Ko
    merci pour votre aide

    voici le code que j'ai développé

    la page 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
    <?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">
        <h:head>
        </h:head>
        <h:body>
            <h:form >
     
                <h:panelGroup id="display0"  > 
                    <div></div>
     
     
                    <p:inputText id="champs1"          value="#{monBean.champs1}"     />
                    <p:commandButton  value="+"   rendered="#{monBean.boutton1}"   action="#{monBean.afficherLigne2()}"  update="display0" />                     
                    <div></div>
     
                     <h:panelGroup  rendered="#{nomDomaines.afficherChamps2}" >
                     <p:inputText id="champs2"      value="#{monBean.champs2}"    />
                    <h:panelGroup>
                    <p:commandButton  value="+"       action="#{monBean.afficherLigne3()}"   rendered="#{monBean.boutton2}"   update="display0"          />      
     
     
                    <div></div>   
                    <h:panelGroup  rendered="#{nomDomaines.afficherChamps3}" >
                    <p:inputText id="champs3"       value="#{monBean .champs3}"    />
                    <h:panelGroup>
                    <div></div> 
     
                    <div></div>                    
                </h:panelGroup>
     
     
            </h:form>
     
        </h:body>
    </html>

    le code 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
    import java.io.Serializable;
    import javax.annotation.PostConstruct;
    import javax.faces.bean.ManagedBean;
     
     
    @ManagedBean
    public class MonBean implements Serializable {
     
        private String champs1;
     
        private String champs2;
     
        private String champs3;
     
        private boolean boutton1;
        private boolean boutton2;
        private boolean boutton3;
     
        private boolean afficherChamps2;
        private boolean afficherChamps3;
     
        @PostConstruct
        public void init() {
            boutton1 = true;
        }
     
        public void afficherLigne2() {
            boutton1 = false;
            boutton2 = true;
            boutton3 = false;
            afficherChamps2 = true;
            afficherChamps3 = false;
        }
     
        public void afficherLigne3() {
            boutton1 = false;
            boutton2 = false;
            boutton3 = true;
            afficherChamps2 = true;
            afficherChamps3 = true;
        }
     
        public boolean getBoutton1() {
            return boutton1;
        }
     
        public void setBoutton1(boolean boutton1) {
            this.boutton1 = boutton1;
        }
     
        public boolean getBoutton2() {
            return boutton2;
        }
     
        public void setBoutton2(boolean boutton2) {
            this.boutton2 = boutton2;
        }
     
        public boolean isBoutton3() {
            return boutton3;
        }
     
        public void setBoutton3(boolean boutton3) {
            this.boutton3 = boutton3;
        }
     
        public boolean isAfficherChamps2() {
            return afficherChamps2;
        }
     
        public void setAfficherChamps2(boolean afficherChamps2) {
            this.afficherChamps2 = afficherChamps2;
        }
     
        public boolean isAfficherChamps3() {
            return afficherChamps3;
        }
     
        public void setAfficherChamps3(boolean afficherChamps3) {
            this.afficherChamps3 = afficherChamps3;
        }
     
        public String getChamps1() {
            return champs1;
        }
     
        public void setChamps1(String champs1) {
            this.champs1 = champs1;
        }
     
        public String getChamps2() {
            return champs2;
        }
     
        public void setChamps2(String champs2) {
            this.champs2 = champs2;
        }
     
        public String getChamps3() {
            return champs3;
        }
     
        public void setChamps3(String champs3) {
            this.champs3 = champs3;
        }
     
    }
    Images attachées Images attachées  

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    ton bean est "request scope", du coup, lors du deuxième click, quand tu soumet le formulaire, le serveur crée un nouveau bean, comme à chaque fois, la valeur afficherChamps2 est false, donc le panelgroup n'est pas rendu, donc le bouton sur lequel tu as cliqué n'existe pas, donc aucune action n'est effectuée.


    Tu dois passer ton bean en sessionscope, par exemple.

  3. #3
    Membre à l'essai
    Homme Profil pro
    Développeur Java
    Inscrit en
    Juin 2013
    Messages
    8
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2013
    Messages : 8
    Points : 11
    Points
    11
    Par défaut
    merci beaucoup Tchize_
    Effectivement j'ai rajouté @ViewScoped à mon bean est c'est OK

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

Discussions similaires

  1. Remplir un champ texte automatiquement via un autre champ texte
    Par Maxime50 dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 31/08/2009, 12h54
  2. Réponses: 9
    Dernier message: 09/01/2007, 11h06
  3. [PHP-JS] champ texte peut il devenir un champ html ?
    Par djedje37et28 dans le forum Langage
    Réponses: 5
    Dernier message: 28/08/2006, 09h16
  4. [Access][SQL] Filtrer un champ text qui peut être NULL
    Par aumax1 dans le forum VBA Access
    Réponses: 1
    Dernier message: 04/04/2006, 08h40
  5. Faire apparaître un champ texte en cliquant sur un select
    Par yoyot dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 15/03/2005, 16h16

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