Skip to Content
author's profile photo Former Member
Former Member

Accessing Session Bean


I have created a simple stateless session bean, and want to call a business method, if the user clicks a button.

Do I need to import a XMI Model for that?

Can I call the bean directly in the view controller or is it better to make the the call in the component controller?

I tried a normal JNDI lookup for the bean in the view controller, but it did not work.

Are there any How To's or Code Snippets on how to do that ?



Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Feb 12, 2004 at 12:04 PM

    Hi Raphael,

    It is possible to call the bean directly. Please find below a code example with EJB usage. This example usses the remote interface of the EJB, because the Web Dynpro application is running in the Web Dynpro Container and not in the EJB container.

    Hope that helps!




    Context jndiCtx = new InitialContext();

    // in the server's name space. Returnvalue: 'java.lang.Object' (RMI/IIOP compatible)

    Object ref = jndiCtx.lookup(" Hello World EJB/HelloWorldEJBBean");

    // casting the jndi lookup() return type 'java.lang.Object' to the bean's EJBHome type

    // using the method 'javax.rmi.PortableRemoteObject.narrow' (EJB1.1):

    HelloWorldEJBHome home = (HelloWorldEJBHome)javax.rmi.PortableRemoteObject.narrow(ref,HelloWorldEJBHome);

    HelloWorldEJB helloWorld = home.create();


    }catch (Exception e) {

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Stefan,

      your code seem to be the same as mine inspite of the difference that I use the JNDI Name ("CounterBean") of my bean.

      My bean is of type "TestHome" (remote home interface) but does have the JNDI name "CounterBean".

      The lookup works correct but the cast throws the error.

      Of course I didn´t set the sharing reference because I cannot do that if referencing a bean on a server somewhere in the world.

      Using J2EE Patterns:

      We will of course use the J2EE Patterns you mentioned in the message to Detlev.

      Regards and a nice weekend to you as well


Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.