Im testing a little aplication in Java EE 6 with EJB 3.1 and JSF 2.0.
The question is that, when I call the Backing bean in JSF with a EL expression, and run the application, I get Exception because this backing bean is inaccesible and is null.
See the image
Here is my JSF code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://ift.tt/kkyg93">
<html xmlns="http://ift.tt/lH0Osb"
xmlns:h="http://ift.tt/HjFrZb"
>
<h:head>
<title>Insertar Usuarios</title>
</h:head>
<h:body>
<h:form id="registro">
<h:panelGrid columns="2">
<h:outputText value="Username:"/>
<h:inputText id="username" value="#{registro.usuario.user_Name}"/>
<h:outputText value="Id:"/>
<h:inputText id="id_user" value="#{registro.usuario.userId}"/>
<h:outputText value="Mensaje:"/>
<h:inputText id="mensaje" value="#{registro.usuario.userMessage}" required="true"/>
<h:commandButton value="Crear usuario" action="#{registro.insertarUsuario()}" />
</h:panelGrid>
<h:messages/>
</h:form>
</h:body>
</html>
Here is my Stateless EJB:
@Stateless
public class NegocioImpl implements Negocio{
@PersistenceContext(unitName = "manager1")
private EntityManager em;
@Override
public void sayHelloFromServiceBean(User user) {
User u = em.find(User.class, user.getUserId());
if(u != null){
System.out.println("Cuenta existente");
}
em.persist(user);
}
public String hola(){
return "hola";
}
}
And finally the backing bean:
@Named
@RequestScoped
public class Registro {
@Inject
private Negocio negocio;
private User usuario;
public Registro(){
usuario = new User();
}
public User getUsuario() {
return usuario;
}
public void setUsuario(User usuario) {
this.usuario = usuario;
}
public void insertarUsuario(){
negocio.sayHelloFromServiceBean(usuario);
}
public void saluda(){
negocio.hola();
}
}
The project structure is make with Intellij IDEA and this is a picture of the project structure:
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire