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 :

Comment accéder à mon EJB à l'aide de JSF2.0


Sujet :

JSF Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de liquideshark
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Septembre 2006
    Messages
    347
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2006
    Messages : 347
    Par défaut Comment accéder à mon EJB à l'aide de JSF2.0
    Salut ,

    Je suis un bleu en JSF 2.0 et j'aimerais accéder à un ejb que j'ai deployé sous glassfish V3, la base de donnée que j'utilise est sur Oracle.
    J'ai créé de coté un client javaapplication pour y accéder voici 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
    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package clientejb3;
    import buss.SnBeanRemote;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Properties;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import mapped.Customer;
    import mapped.Dept;
     
    import mapped.Product;
     
     
     
     
     
    /**
     *
     * @author liquideshark
     */
    public class Scott {
     
         /**
         * @param args the command line arguments
         */
     
       public static List getCustom(){
          Properties props = new Properties();
          props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
          props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
          SnBeanRemote rcom =null;
            try {
                InitialContext ic = new InitialContext(props);
                 rcom = (SnBeanRemote) ic.lookup("buss.SnBeanRemote");
     
         //List allCust = rcom.getCustomers();
     
     
            } catch (NamingException ex) {
                Logger.getLogger(Exemple2.class.getName()).log(Level.SEVERE, null, ex);
            }
     
          return rcom.getCustomers();
     
      }
     
     
     
     
        public static void main(String[] args) {
            // TODO code application logic here
     
      Properties props = new Properties();
     // props.setProperty("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");
     // props.setProperty("java.naming.factory.url.pkgs","com.sun.enterprise.naming");
    //  props.setProperty("java.naming.factory.state","com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
     
     
      // optional.  Defaults to localhost.  Only needed if web server is running
      // on a different host than the appserver
      props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
     
      // optional.  Defaults to 3700.  Only needed if target orb port is not 3700.
      props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
     
            try {
                InitialContext ic = new InitialContext(props);
                SnBeanRemote rcom = (SnBeanRemote) ic.lookup("buss.SnBeanRemote");
     
     
     
     
     
         List allCust = rcom.getCustomers();
         List allDept = rcom.getDepartement();
          List allProduct = rcom.getProduit();
     
     System.out.println("***********  Customer  **************\n\n");
                for (Iterator iter = allCust.iterator(); iter.hasNext();) {
                    Customer cust = (Customer) iter.next();
                    System.out.println(":Addre:"+cust.getAddress()+":City:"+cust.getCity()+":Name:"+cust.getName()+":Phone:"+cust.getPhone());
                }
      System.out.println("***********  Departement  **************\n\n");
      for (Iterator iter = allDept.iterator(); iter.hasNext();) {
                    Dept dep = (Dept) iter.next();
                    System.out.println(":Name :"+dep.getDname()+":Localisation: "+dep.getLoc()+":Depnumer: "+dep.getDeptno());
                }
      System.out.println("***********  Produits  ************** \n\n");
      for (Iterator iter = allProduct.iterator(); iter.hasNext();) {
                    Product prod = (Product) iter.next();
                    System.out.println("Description "+prod.getDescrip()+"ID produit: "+prod.getProdid());
                }
     
     
            } catch (NamingException ex) {
                Logger.getLogger(Exemple2.class.getName()).log(Level.SEVERE, null, ex);
            }
     
     
     List lilo = getCustom();
     
     System.out.println("***********  %%%%%%%%%Customer LILO%%%%%%%  **************\n\n");
                for (Iterator iter = lilo.iterator(); iter.hasNext();) {
                    Customer cust = (Customer) iter.next();
                    System.out.println(":Addre:"+cust.getAddress()+":City:"+cust.getCity()+":Name:"+cust.getName()+":Phone:"+cust.getPhone());
                }
     
     
     
     
        }
     
    }

    et voici le résultat :

    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
    1 avr. 2010 10:31:04 com.sun.enterprise.transaction.JavaEETransactionManagerSimplified initDelegates
    INFO: Using com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate as the delegate
    ***********  Customer  **************
     
     
    :Addre:345 VIEWRIDGE:City:BELMONT:Name:JOCKSPORTS:Phone:598-6609
    :Addre:490 BOLI RD.:City:REDWOOD CITY:Name:TKB SPORT SHOP:Phone:368-1223
    :Addre:9722 HAMILTON:City:BURLINGAME:Name:VOLLYRITE:Phone:644-3341
    :Addre:HILLVIEW MALL:City:BURLINGAME:Name:JUST TENNIS:Phone:677-9312
    :Addre:574 SURRY RD.:City:CUPERTINO:Name:EVERY MOUNTAIN:Phone:996-2323
    :Addre:3476 EL PASEO:City:SANTA CLARA:Name:K + T SPORTS:Phone:376-9966
    :Addre:908 SEQUOIA:City:PALO ALTO:Name:SHAPE UP:Phone:364-9777
    :Addre:VALCO VILLAGE:City:SUNNYVALE:Name:WOMENS SPORTS:Phone:967-4398
    :Addre:98 LONE PINE WAY:City:HIBBING:Name:NORTH WOODS HEALTH AND FITNESS SUPPLY CENTER:Phone:566-9123
    ***********  Departement  **************
     
     
    :Name :ACCOUNTING:Localisation: NEW YORK:Depnumer: 10
    :Name :RESEARCH:Localisation: DALLAS:Depnumer: 20
    :Name :SALES:Localisation: CHICAGO:Depnumer: 30
    :Name :OPERATIONS:Localisation: BOSTON:Depnumer: 40
    ***********  Produits  ************** 
     
     
    Description ACE TENNIS RACKET IID produit: 100860
    Description ACE TENNIS RACKET IIID produit: 100861
    Description ACE TENNIS BALLS-3 PACKID produit: 100870
    Description ACE TENNIS BALLS-6 PACKID produit: 100871
    Description ACE TENNIS NETID produit: 100890
    Description SP TENNIS RACKETID produit: 101860
    Description SP JUNIOR RACKETID produit: 101863
    Description RH: "GUIDE TO TENNIS"ID produit: 102130
    Description SB ENERGY BAR-6 PACKID produit: 200376
    Description SB VITA SNACK-6 PACKID produit: 200380
    ***********  %%%%%%%%%Customer LILO%%%%%%%  **************
     
     
    :Addre:345 VIEWRIDGE:City:BELMONT:Name:JOCKSPORTS:Phone:598-6609
    :Addre:490 BOLI RD.:City:REDWOOD CITY:Name:TKB SPORT SHOP:Phone:368-1223
    :Addre:9722 HAMILTON:City:BURLINGAME:Name:VOLLYRITE:Phone:644-3341
    :Addre:HILLVIEW MALL:City:BURLINGAME:Name:JUST TENNIS:Phone:677-9312
    :Addre:574 SURRY RD.:City:CUPERTINO:Name:EVERY MOUNTAIN:Phone:996-2323
    :Addre:3476 EL PASEO:City:SANTA CLARA:Name:K + T SPORTS:Phone:376-9966
    :Addre:908 SEQUOIA:City:PALO ALTO:Name:SHAPE UP:Phone:364-9777
    :Addre:VALCO VILLAGE:City:SUNNYVALE:Name:WOMENS SPORTS:Phone:967-4398
    :Addre:98 LONE PINE WAY:City:HIBBING:Name:NORTH WOODS HEALTH AND FITNESS SUPPLY CENTER:Phone:566-9123
    BUILD SUCCESSFUL (total time: 3 seconds)
    Enfin tous ce passe bien.

    Comment ? pourrai-je implémente cela sous un projet JSF2.0 merci.

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    191
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 191
    Par défaut
    Tu as essayé avec l'annotation @EJB ?
    Exemple d'utilisation (chapitre "Creating JSF Managed Beans")

    Article JSF 2.0 intéressant.

  3. #3
    Membre éprouvé Avatar de anisj1m
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2006
    Messages
    1 067
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Tunisie

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

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 067
    Par défaut
    votre question n'est pas précis.
    mais pour ce qui est connu, le passage de jsf au ejb se fait a travers jndi

    le lookup

  4. #4
    Membre éclairé Avatar de liquideshark
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Septembre 2006
    Messages
    347
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2006
    Messages : 347
    Par défaut
    Salut à tous,

    Ma question est : comment utiliser mon EJB dans un projet web du type JSF2.0.

    Dans un projet java j'y accede comme suit:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     Properties props = new Properties();
          props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
          props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
          SnBeanRemote rcom =null;
            try {
                InitialContext ic = new InitialContext(props);
                 rcom = (SnBeanRemote) ic.lookup("buss.SnBeanRemote");
    Je ne sais pas le faire avec JSF.

    Mon EJb est deployé sous glassfish V3. J'accède par remote. 100.100.100.78:3700

    Merci encore

  5. #5
    Membre éclairé Avatar de liquideshark
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Septembre 2006
    Messages
    347
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2006
    Messages : 347
    Par défaut
    Re salut,

    Ce que j'ai besoin de faire c'est :

    J'ai 2 serveurs :
    * Tomcat sur 100.100.100.77, qui contient mon application client web en JSF.
    * Glassfish V3 sur 100.100.100.78 qui contient mon EJB.

    mon probléme est comment faire, que l'application sous tomcat puisse acceder a mon ejb sous glassfish.

    Merci encore de votre aide

  6. #6
    Membre éprouvé Avatar de anisj1m
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2006
    Messages
    1 067
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Tunisie

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

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 067
    Par défaut
    très simple,

    Dans la méthode qui existe dans ton bean (classe java (framework jsf)) écrire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    InitialContext ic = new InitialContext(props);
                 rcom = (SnBeanRemote) ic.lookup("buss.SnBeanRemote");

  7. #7
    Membre éclairé Avatar de liquideshark
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Septembre 2006
    Messages
    347
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Service public

    Informations forums :
    Inscription : Septembre 2006
    Messages : 347
    Par défaut
    Salut,

    J'ai essayé plusieurs fois ça n'a rien donné, j'ai cette erreur qui est retourné:

    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
    26 avr. 2010 16:08:39 org.apache.catalina.startup.Catalina start
    INFO: Server startup in 8684 ms
    javax.naming.NameNotFoundException: Le Nom buss.SnBeanRemote n'est pas lié à ce Contexte
            at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
            at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
            at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
            at javax.naming.InitialContext.lookup(InitialContext.java:392)
            at clientejb3.Scott.getCustom(Scott.java:43)
            at org.apache.jsp.newjsp_jsp._jspService(newjsp_jsp.java:99)
            at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
            at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
            at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
            at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
            at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
            at java.lang.Thread.run(Thread.java:619)
    j'appele ce code dans une page jsp:

    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package clientejb3;
    import buss.SnBeanRemote;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Properties;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import mapped.Customer;
    import mapped.Dept;
     
    import mapped.Product;
     
     
     
     
     
    /**
     *
     * @author liquideshark
     */
    public class Scott {
     
         /**
         * @param args the command line arguments
         */
     
       public static List getCustom(){
          Properties props = new Properties();
          props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
          props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
          SnBeanRemote rcom =null;
            try {
                InitialContext ic = new InitialContext(props);
                 rcom = (SnBeanRemote) ic.lookup("buss.SnBeanRemote");
     
         //List allCust = rcom.getCustomers();
     
     
            } catch (NamingException ex) {
                Logger.getLogger(Exemple2.class.getName()).log(Level.SEVERE, null, ex);
            }
     
          return rcom.getCustomers();
     
      }
     
     
     
     
        public static void main(String[] args) {
            // TODO code application logic here
     
      Properties props = new Properties();
     // props.setProperty("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");
     // props.setProperty("java.naming.factory.url.pkgs","com.sun.enterprise.naming");
    //  props.setProperty("java.naming.factory.state","com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
     
     
      // optional.  Defaults to localhost.  Only needed if web server is running
      // on a different host than the appserver
      props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
     
      // optional.  Defaults to 3700.  Only needed if target orb port is not 3700.
      props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
     
            try {
                InitialContext ic = new InitialContext(props);
                SnBeanRemote rcom = (SnBeanRemote) ic.lookup("buss.SnBeanRemote");
     
     
     
     
     
         List allCust = rcom.getCustomers();
         List allDept = rcom.getDepartement();
          List allProduct = rcom.getProduit();
     
     System.out.println("***********  Customer  **************\n\n");
                for (Iterator iter = allCust.iterator(); iter.hasNext();) {
                    Customer cust = (Customer) iter.next();
                    System.out.println(":Addre:"+cust.getAddress()+":City:"+cust.getCity()+":Name:"+cust.getName()+":Phone:"+cust.getPhone());
                }
      System.out.println("***********  Departement  **************\n\n");
      for (Iterator iter = allDept.iterator(); iter.hasNext();) {
                    Dept dep = (Dept) iter.next();
                    System.out.println(":Name :"+dep.getDname()+":Localisation: "+dep.getLoc()+":Depnumer: "+dep.getDeptno());
                }
      System.out.println("***********  Produits  ************** \n\n");
      for (Iterator iter = allProduct.iterator(); iter.hasNext();) {
                    Product prod = (Product) iter.next();
                    System.out.println("Description "+prod.getDescrip()+"ID produit: "+prod.getProdid());
                }
     
     
            } catch (NamingException ex) {
                Logger.getLogger(Exemple2.class.getName()).log(Level.SEVERE, null, ex);
            }
     
     
     List lilo = getCustom();
     
     System.out.println("***********  %%%%%%%%%Customer LILO%%%%%%%  **************\n\n");
                for (Iterator iter = lilo.iterator(); iter.hasNext();) {
                    Customer cust = (Customer) iter.next();
                    System.out.println(":Addre:"+cust.getAddress()+":City:"+cust.getCity()+":Name:"+cust.getName()+":Phone:"+cust.getPhone());
                }
     
     
     
     
        }
     
    }
    Merci pour votre aide

  8. #8
    Membre éprouvé Avatar de anisj1m
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2006
    Messages
    1 067
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Tunisie

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

    Informations forums :
    Inscription : Juillet 2006
    Messages : 1 067
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Interfaceejb ejb = (Interfaceejb) lookup("implementationEjb#package.Interfaceejb");

Discussions similaires

  1. Réponses: 4
    Dernier message: 18/05/2010, 16h56
  2. Comment accéder à mon serveur depuis l'extérieur?
    Par Bassas dans le forum Tomcat et TomEE
    Réponses: 1
    Dernier message: 08/02/2010, 13h24
  3. Comment accéder à mon serveur JBoss
    Par fgiuliano dans le forum Wildfly/JBoss
    Réponses: 5
    Dernier message: 03/06/2009, 21h31
  4. [EJB3] [JSF] Impossible d'accéder à mon EJB local..
    Par petrone dans le forum Java EE
    Réponses: 8
    Dernier message: 10/02/2009, 10h53
  5. [Debutant] Comment accéder à mon application web depuis un autre pc?
    Par Perfourras dans le forum Glassfish et Payara
    Réponses: 5
    Dernier message: 10/06/2008, 21h09

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