Solved

Access to a session bean from a request bean

Posted on 2009-06-30
7
611 Views
Last Modified: 2012-05-07
Hi!

I want to know how to access to my SessionBean from the java code of the request bean?

I've only done this from the JSF page with the #{...}

Thanks you !
0
Comment
Question by:Nargzul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 7

Expert Comment

by:gudii9
ID: 24751106
>>>I've only done this from the JSF page with the #{...}

Can you please elaborate more.
0
 
LVL 1

Author Comment

by:Nargzul
ID: 24751239
I've only call bean in the jsf code.

like:

<h:outputText value="#{MySessionBean.myvalueA}"/>

And now, I want to to know, to to access to this same value, but from a request Bean.

So how do we do? We just create a

MySessionBean msb = new MySessionBean(); ?

and access by this object after?

Must we do a lookup to get this session bean?
0
 
LVL 20

Expert Comment

by:a_b
ID: 24751458
You will have to do la lookup to the session bean, a better idea might be to do the lookup through the request bean, and access the methods through there.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:jwenting
ID: 24751773
See any Java EE tutorial for the application server you're using.
It's not that hard, but the exact details are somewhat specific to the server the EJB is running on (especially the parameters to the JNDI lookup).
It also depends on the version of the EJB. The lookup for EJB 3 is quite different from those of earlier versions.

In general (abbreviated):
- do JNDI lookup
- retrieve looked-up bean
- cast to EJB interface
- call methods
0
 
LVL 1

Author Comment

by:Nargzul
ID: 24753456
But, session/request/.... beans are a part of EJB???

Have you some code exemple? It's the only thing I need :)

I use glassfish.
0
 
LVL 20

Expert Comment

by:a_b
ID: 24753536
If you want to lookup a session bean you need to do this -

        Properties properties = new Properties();;
       
        properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
        properties.put(Context.PROVIDER_URL, "localhost:1099");

        InitialContext context;

        try
        {
            context = new InitialContext(properties);
            TestbeanLocalInterface module = (TestbeanLocalInterface) context.lookup("Testbean/local");
           
        }
        catch (NamingException e)
        {
            e.printStackTrace();
        }
0
 
LVL 1

Accepted Solution

by:
Nargzul earned 0 total points
ID: 24768052
If JSF can access to the Session Bean without interface, we can do it too!

After many research I've find this:


(sessionInformations is my sessionBean). I've tested and it works really good, and I find this really simplier than create a new interface for each Session Bean.

(In addition, I will say, it's really much easier to use injection to access to EJB)

sessionInformations sessInf = (sessionInformations) FacesContext.getCurrentInstance().getApplication().createValueBinding("#{sessionInformations}").getValue(FacesContext.getCurrentInstance());

Open in new window

0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question