This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Trouble in using @EJB in a ManagedBean... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Trouble in using @EJB in a ManagedBean..." Watch "Trouble in using @EJB in a ManagedBean..." New topic

Trouble in using @EJB in a ManagedBean...

Paterne Gaye-Guingnido

Joined: Jun 17, 2008
Posts: 5
Hi all!
I'm using Netbeans 6.1 + Glassfish v2 + JSF
I working on an Java EE project with 3 module (war, ejb and swing client)
My app-client and my ejb module work without difficulty.

Now I'm trying to create an jsf page with will show the data of my database

I add my EJB module to my WAR module

I create a managedbean EvaluationController in my war project
In the managedbean, I declare an EJB with @EJB

I the face-config.xml I declare my managedbean with I call "evaluationLocal"

I create an page evaluations.jsp where I use the managedbean "evaluationLocal"

Here are my files:


****************The managedbean : EvaluationController*************

When I execute the page, I have the message:

I use the "verify" tool of Netbans and I have the message

Please can you tell me where is my mistake?
Armen Arzumanyan

Joined: Jun 18, 2008
Posts: 13
Instead @EJB you must use lookup

here is a working example

private BeanRemote remote;//remote interface of your session bean

public String start() throws NamingException {
String navigation = "null";
try {
Hashtable environment = new Hashtable();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
environment.put(Context.URL_PKG_PREFIXES, "org.jboss.naming rg.jnp.interfaces");
environment.put(Context.PROVIDER_URL, "jnp://localhost:1099");
InitialContext context = new InitialContext(environment);
remote = (BeanRemote) context.lookup("wn/Bean/remote"); // wn project name , Bean - name of session bean
System.out.println("-->> lookup object successfully");
wnUser = new WnUser();/// ----------> your entity bean

remote.create(wnUser); (calling method from remote interface ....
Paterne Gaye-Guingnido

Joined: Jun 17, 2008
Posts: 5
Thanks for your answer Armen Arzumanyan
But if I choose your proposal, I'll use
remote interface instead of local.

I also want to know which mistake I make.
Or if it is a bug of Glassfis/Netbeans.
I agree. Here's the link:
subject: Trouble in using @EJB in a ManagedBean...
It's not a secret anymore!