aspose file tools*
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 Spring in Action 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
Author

Trouble in using @EJB in a ManagedBean...

Paterne Gaye-Guingnido
Greenhorn

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


=1==============
I add my EJB module to my WAR module

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

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

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


Here are my files:
****************face-config.xml**************************


****************sun-web.xml*******************************


****************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
Greenhorn

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

this.wnUser.setEmail(email);
this.wnUser.setPassword(password);
this.wnUser.setFirstname(firstname);
this.wnUser.setLastname(lastname);
this.wnUser.setGender(gender);
this.wnUser.setBirthday(birthdate);
this.wnUser.setMobilePhone(mobilePhone);
this.wnUser.setCreateDatetime(createDatetime);
this.wnUser.setCreateDatetime(createDatetime);
remote.create(wnUser); (calling method from remote interface ....
Paterne Gaye-Guingnido
Greenhorn

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: http://aspose.com/file-tools
 
subject: Trouble in using @EJB in a ManagedBean...