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 :

Un AjaxBehaviour ajouté programmatiquement à un commandLink n'a pas marché.


Sujet :

JSF Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du Club
    Homme Profil pro
    Ingénieur avant-vente
    Inscrit en
    Septembre 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur avant-vente
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Septembre 2012
    Messages : 3
    Par défaut Un AjaxBehaviour ajouté programmatiquement à un commandLink n'a pas marché.
    Salut !

    Depuis 2 jours j'essaie de trouver une solution à ce problème mais sans succès.

    A une form dans une page .xhtml, j'ai réussi à ajouter un commandLink par du code java (dynamiquement) et cette opération se déroule convenablement puisque j'arrive à voir cet élément dans la page après un rafraîchissement partiel avec ajax du block dans lequel j'ai ajouté le commandLink.

    J'essaie d'ajouter un AjaxBehaviour au commandLink (j'ai essayé de deux façon s: 1- après avoir ajouter le commandLink au view , je le récupère avec un form.findcompoent('id du commandlink') Et 2-J'ajoute le AjaxBehaviour au commandLink avant d'ajouter ce dernier au view.

    Et puis, pour l'ajout de l'ajax behaviour lui même j'ai aussi essayé de faire de deux façons (voir le managed Bean : method 1 et method 2) Mais aucune façon n'a reussit.


    voila mon index.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
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE html>
    <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:p="http://primefaces.org/ui"
    	xmlns:ui="http://java.sun.com/jsf/facelets"
    	xmlns:c="http://java.sun.com/jsp/jstl/core">
     
    <h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>dyn add comps test </title>
     
     
    </h:head>
    <body>
    <h:form id="form1">
     
     
    <h:commandLink value="cliick me">
    <f:ajax event="click" listener="#{myBean.sayHelloToName}"/>
    </h:commandLink>
     
    <br />
    <br />
     
    <!--  une fois le commandLink plus haut cliqué , un autre commandLink s ajoute dynamiquement au block qui suit :  -->
     
    <h:panelGroup id="foo" layout="block" style="position:absolute;width:70px;height:30px;border:1px solid blue;">
     
    </h:panelGroup>
     
    </h:form>
    </body>
    </html>

    et voila mon Managed 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
    107
    108
    109
    110
     
    package mybeans;
     
    import javax.el.ExpressionFactory;
    import javax.el.MethodExpression;
    import javax.faces.application.Application;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.SessionScoped;
    import javax.faces.component.UIComponent;
    import javax.faces.component.behavior.AjaxBehavior;
    import javax.faces.component.html.HtmlCommandLink;
    import javax.faces.component.html.HtmlPanelGroup;
    import javax.faces.context.FacesContext;
    import javax.faces.event.AjaxBehaviorEvent;
     
    import org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl;
    import org.primefaces.context.RequestContext;
     
    @ManagedBean
    @SessionScoped
    public class MyBean {
     
    	public String name;
     
    	public String getName() {
    		return name;
    	}
     
    	public void setName(String name) {
    		this.name = name;
    	}
     
            //Le listener Handler pour le commandLink qui s'ajoute dynamiquement :
    	public void sayHelloToName2(AjaxBehaviorEvent abe){
     
    		System.out.println("!!!-->>>>>  the Ajax Behaviour Works !!!!! ");
     
    	}
     
     
    	public void sayHelloToName(AjaxBehaviorEvent abe){
     
     
    		System.out.println("sayHelloToName is running ! ");
     
    		FacesContext fc = FacesContext.getCurrentInstance();
    		Application application = fc.getApplication();
    	    ExpressionFactory ef =fc.getApplication().getExpressionFactory();
     
     
    	    UIComponent form1 =	fc.getViewRoot().findComponent("form1");
     
    	    if(form1!=null){
     
    	    	//Creating the commandLink
    	    	HtmlCommandLink mynewcmdlink = (HtmlCommandLink) application.createComponent(HtmlCommandLink.COMPONENT_TYPE);
     			mynewcmdlink.setId("mynewcmdlink");
    			mynewcmdlink.setValue("clickme2!!");
     
     
     
    			//Adding the commandLink to the form
    			HtmlPanelGroup foo = (HtmlPanelGroup) form1.findComponent("foo"); 
    			foo.getChildren().add(mynewcmdlink);
     
     
     
    			//creating the Ajax Behaviour method 1
    //			MethodExpression me = ef.createMethodExpression( fc.getELContext(), "#{myBean.sayHelloToName2}", String.class, new Class[0]);
    //			AjaxBehavior ajaxBehavior = new AjaxBehavior();
     
    			//ajaxBehavior.setListener( me );
    			//ajaxBehavior.addAjaxBehaviorListener( new AjaxBehaviorListenerImpl( me ) );
     
    			//creating the Ajax Behaviour method 2
    			AjaxBehavior sayhelloBehavior = new AjaxBehavior();
    			sayhelloBehavior.addAjaxBehaviorListener(new SayhelloListener());
    			sayhelloBehavior.setTransient(true);
     
     
     
    			//////////Adding the Ajax Behaviour
    			//for the method 1
    			//mynewcmdlink = (HtmlCommandLink) fc.getViewRoot().findComponent("form1").findComponent("mynewcmdlink"); 
    			//mynewcmdlink.addClientBehavior( "sayHello", ajaxBehavior);
     
    			//for the method 2
    			mynewcmdlink = (HtmlCommandLink) fc.getViewRoot().findComponent("form1").findComponent("mynewcmdlink");
    			mynewcmdlink.addClientBehavior("sayhelloBehavior", sayhelloBehavior);
     
     
     
    			RequestContext context = RequestContext.getCurrentInstance();			
    			context.update("form1");
    			context.update("form1:foo"); 
     
    	    }else
    	    	System.out.println("form1 is null!!");
     
     
     
     
     
     
    	}
     
     
     
     
    }




    Merci pour votre aide !!!

  2. #2
    Futur Membre du Club
    Homme Profil pro
    Ingénieur avant-vente
    Inscrit en
    Septembre 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur avant-vente
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Septembre 2012
    Messages : 3

Discussions similaires

  1. Réponses: 18
    Dernier message: 11/04/2014, 15h40
  2. Réponses: 8
    Dernier message: 16/01/2011, 22h38
  3. ajout liste déroulante automatiquement [possible ou pas]
    Par rouxfab dans le forum VBA Access
    Réponses: 3
    Dernier message: 14/04/2008, 23h38
  4. CommandLink ne fonctionne pas
    Par dev7 dans le forum JSF
    Réponses: 3
    Dernier message: 22/01/2007, 18h14
  5. [MySQL] Ajout de données qui ne fonctionne pas
    Par paterson dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 01/05/2006, 20h28

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