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 :

Problème avec ma liste déroulante JSF 2.0


Sujet :

JSF Java

  1. #1
    Membre à l'essai
    Femme Profil pro
    Inscrit en
    Avril 2012
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Avril 2012
    Messages : 19
    Points : 14
    Points
    14
    Par défaut Problème avec ma liste déroulante JSF 2.0
    Bonjour a tous;

    j'ai un problème avec ma liste déroulante. Je veux recuperer l'item selectionné mais j'y arrive pas voila le code .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
     
    <p:dialog widgetVar="composeDlg" modal="true" header="Nouvelle reclamation" width="530" height="300" showEffect="fade" hideEffect="fade">
    <h:form>
            <h:outputText value="Objet: "/> 
            <p:selectOneListbox id="scroll" value="#{recBean.selectedType}" style="height:100px ;width:220px" >  
            <f:selectItems var="a" id ="scrol" value="#{recBean.listTypeRec}" itemLabel="#{a.libelleTypeRec}"  itemValue="#{a}"/>  
            </p:selectOneListbox>
            <p:keyboard id="val" value="#{recBean.value}"/>
     
     <p:commandButton value="Send" actionListener="#{recBean.envoieRec}"/>
     <p:commandButton value="Cancel" onclick="composeDlg.hide()" type="button"/>
     
    </h:form>
    </p:dialog>


    le code de recBean:
    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
    @ManagedBean(name="recBean")
    @SessionScoped
    public class ReclamationBean implements Serializable{
     
    @ManagedProperty(value="#{reclamationService}")
    private RecService reclamationService;
     
    @ManagedProperty(value="#{loginBean}")
    private LoginBean loginBean;  
     
     
    private TypeReclamation selectedType;
        @Autowired
    	private List<TypeReclamation> listTypeRec;
    	private Reclamation rec;
     
    	public String value; 
     
    	public ReclamationBean()
    	{
    	}
     
     
     
        public String getValue() {  
            return value;  
        }  
     
        public void setValue(String value) {  
            this.value = value;  
        } 
     
     
    public TypeReclamation getSelectedType() {
    	return selectedType;
    }
     
    public void setSelectedType(TypeReclamation selectedType) {
    	this.selectedType = selectedType;
    }
     
     
    public Reclamation getRec() {
    	return rec;
    }
     
    public void setRec(Reclamation rec) {
    	this.rec = rec;
    }
     
     
     
    public List<TypeReclamation> getListTypeRec() {
    	return listTypeRec;
    }
     
     
    public void setListTypeRec(List<TypeReclamation> listTypeRec) {
    	this.listTypeRec = listTypeRec;
    }
     
     
    public void envoieRec(ActionEvent actionEvent) {  
    rec=new Reclamation();
    rec.setIdAbonne(idAbonne);
    //System.out.println(idAbonne);
     
    //System.out.println( selectedType);
    rec.setIdTypeRec(selectedType.getIdTypeRec());	
     
    reclamationService.ajoutRec(rec);
    System.out.print("oketto");
    }
     
    public LoginBean getLoginBean() {
    	return loginBean;
    }
     
    public void setLoginBean(LoginBean loginBean) {
    	this.loginBean = loginBean;
    }
     
    public void setReclamationService(RecService reclamationService) {
    	this.reclamationService = reclamationService;
    }
     
    public RecService getReclamationService() {
    	return reclamationService;
    }
     
    @PostConstruct
    public void extraireType ()
    {
    listTypeRec = reclamationService.findTypeRec();
    k =loginBean.k;
    idAbonne= k.getIdAbonne();
     
     
    }
    public int getTyp() {
    	return typ;
    }
     
     
     
    public void setTyp(int typ) {
    	this.typ = typ;
    }
    Abonne k;
    public String nomAbonne;
    public int idAbonne;
    public int typ;
     
    public int getIdAbonne() {
    	return idAbonne;
    }
     
     
     
    public void setIdAbonne(int idAbonne) {
    	this.idAbonne = idAbonne;
    }
     
     
     
    public Abonne getK() {
    	return k;
    }
     
     
     
    public void setK(Abonne k) {
    	this.k = k;
    }
     
     
     
    public String getNomAbonne() {
    	return nomAbonne;
    }
     
     
     
    public void setNomAbonne(String nomAbonne) {
    	this.nomAbonne = nomAbonne;
    }

    le but: l'envoie d'une réclamation par un client déjà authentifier alors il faut que j'enregistre cette réclamation avec l'id de abonné ainsi que l'id de type de la réclamation choisie.

    merci d'avance

  2. #2
    Membre chevronné
    Avatar de fxrobin
    Homme Profil pro
    Architecte SI, Java Fan, API Manager
    Inscrit en
    Novembre 2007
    Messages
    875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Architecte SI, Java Fan, API Manager
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Novembre 2007
    Messages : 875
    Points : 2 112
    Points
    2 112
    Par défaut
    Salut,

    il te faut utiliser un "converter".

    Le plus simple est d'utiliser ce Converter générique que j'avais posté il y a qqs mois :

    http://www.developpez.net/forums/d11...ique-securise/
    Moins on code, moins il y a de bug ... et vice-versa ainsi qu'inversement ...

  3. #3
    Membre du Club
    Inscrit en
    Août 2007
    Messages
    260
    Détails du profil
    Informations forums :
    Inscription : Août 2007
    Messages : 260
    Points : 43
    Points
    43
    Par défaut
    hi fxrobin moi aussi j'ai ce problème, c'est quoi un converter pourquoi on doit l'utiliser si on veux retourner un élément de la liste ??

  4. #4
    Membre à l'essai
    Femme Profil pro
    Inscrit en
    Avril 2012
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Avril 2012
    Messages : 19
    Points : 14
    Points
    14
    Par défaut
    merci beaucoup pour votre réponse! mais je crois que j'ai un problème voila l'exception:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    javax.el.ELException: /pages/reclamation.xhtml @47,147 converter="#{genericSecuredConverter}": Cannot convert com.fst.projet.service.GenericSecuredConverter@100124f of type class com.fst.projet.service.GenericSecuredConverter to interface javax.faces.convert.Converter
    en faite, j'été obligé de modifier un peu le code ( c'est java qui a imposé) voila le code:

    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
    @ManagedBean
    @ViewScoped
    public class GenericSecuredConverter implements Converter, Serializable {
     
     
    	private Map <UUID, Object> temporaryStore = new HashMap <UUID, Object> ();
     
    	//public Object getAsObject(FacesContext context, UIComponent component, String value) {
           // return temporaryStore.get(UUID.fromString(value));
        //}
     public String getAsString(FacesContext context, UIComponent component, Object value) {
            UUID id = UUID.randomUUID();
            temporaryStore.put(id, value);
            return id.toString();
        }
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
    	// TODO Auto-generated method stub
    	return temporaryStore.get(UUID.fromString(value));
    }
     
    @Override
    public Object convert(Class arg0, Object arg1) {
    	// TODO Auto-generated method stub
    	return null;
    }
    }

    comment je peux faire dans ce cas ?

  5. #5
    Membre chevronné
    Avatar de fxrobin
    Homme Profil pro
    Architecte SI, Java Fan, API Manager
    Inscrit en
    Novembre 2007
    Messages
    875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Architecte SI, Java Fan, API Manager
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Novembre 2007
    Messages : 875
    Points : 2 112
    Points
    2 112
    Par défaut
    Tu n'as pas du faire le bon import d'interface Converter

    car un Converter JSF n'impose pas la méthode convert() ;-)

    Montre le converter en entier.
    Moins on code, moins il y a de bug ... et vice-versa ainsi qu'inversement ...

  6. #6
    Membre chevronné
    Avatar de fxrobin
    Homme Profil pro
    Architecte SI, Java Fan, API Manager
    Inscrit en
    Novembre 2007
    Messages
    875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Architecte SI, Java Fan, API Manager
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Novembre 2007
    Messages : 875
    Points : 2 112
    Points
    2 112
    Par défaut
    Citation Envoyé par yous18 Voir le message
    hi fxrobin moi aussi j'ai ce problème, c'est quoi un converter pourquoi on doit l'utiliser si on veux retourner un élément de la liste ??
    Parce que tout ce qui est généré en HTML est du String ... il faut donc un moyen côté java de récupérer une instance en fonction d'une String et inversement de générer une String en fonction d'une instance ...
    Moins on code, moins il y a de bug ... et vice-versa ainsi qu'inversement ...

  7. #7
    Membre à l'essai
    Femme Profil pro
    Inscrit en
    Avril 2012
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Femme

    Informations forums :
    Inscription : Avril 2012
    Messages : 19
    Points : 14
    Points
    14
    Par défaut
    ouiiiii vous avez raison fxrobin votre code marche trés bien mercii infiniment

  8. #8
    Membre chevronné
    Avatar de fxrobin
    Homme Profil pro
    Architecte SI, Java Fan, API Manager
    Inscrit en
    Novembre 2007
    Messages
    875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Architecte SI, Java Fan, API Manager
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Novembre 2007
    Messages : 875
    Points : 2 112
    Points
    2 112
    Par défaut


    La "liste déroulante" est toujours la chose qui pose le plus de "problème" à ceux qui débutent en JSF ... donc tu n'es pas la première ni la dernière

    N'oublie pas de cliquer sur "Résolu"
    Moins on code, moins il y a de bug ... et vice-versa ainsi qu'inversement ...

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

Discussions similaires

  1. [JSF / Seam] Problème avec la liste déroulante
    Par khattary11 dans le forum JSF
    Réponses: 0
    Dernier message: 27/04/2011, 11h22
  2. Problème avec une liste déroulante.
    Par kupae dans le forum IHM
    Réponses: 9
    Dernier message: 09/07/2008, 10h12
  3. problème avec une liste déroulante
    Par valouche dans le forum Macros et VBA Excel
    Réponses: 11
    Dernier message: 30/05/2007, 09h01
  4. [Débutant] problème avec une liste déroulante
    Par stan21 dans le forum Access
    Réponses: 3
    Dernier message: 12/07/2006, 14h52

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