[jboss-user] [EJB3] - Re: EJB 3.1, CDI, JSF 2 ERROR java.lang.NullPointerException
Phanor Coll
do-not-reply at jboss.com
Fri Mar 16 23:31:54 EDT 2012
Phanor Coll [https://community.jboss.org/people/pcoll] created the discussion
"Re: EJB 3.1, CDI, JSF 2 ERROR java.lang.NullPointerException"
To view the discussion, visit: https://community.jboss.org/message/724454#724454
--------------------------------------------------------------
it worked whe using @EJB instead of @Inject thanks, now I have another newbee question.. If the programming rule is that every stateless,stafull bean has to have at least one business interface, why doesnt this code works?
*@ManagedBean(name="message")*
public class index {
@EJB
MyBean bean;
public String getMensaje(){
return "Netbeans + JbossAS 7.1 do rock! " + bean.hola();
}
}
*@Stateless*
public class MyBean implements MybeanInterface {
public String hola(){
return "it's true!";
}
}
public interface MybeanInterface {
String hola();
}
Instead of injecting the SLSB like before I have to use JNDI, It worked like this:
*@ManagedBean(name="message")*
public class index {
public String getMensaje(){
InitialContext context;
try {
context = new InitialContext();
m = (MybeanInterface) context.lookup("java:global/practicaejb/MyBean!practica.interfaces.MybeanInterface");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "Netbeans + JbossAS 7.1 do rock! " + m.hola();
}
whats the difference?.. and sorry for this question, this is probably EJB 101, but like I said before, this is a newbe question..
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/724454#724454]
Start a new discussion in EJB3 at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120316/007c5c8a/attachment.html
More information about the jboss-user
mailing list