Modification-Error in the creation of an instance with jsf-spring-hibernate-mysql

0

I already asked this question previously but now it gives me another error product of a change. I am a beginner in this Spring-Hibernate (I know the essentials). I have created in Netbean a login with hibernate (annotations) and access to MySql but when I added Spring and its annotations I got stuck, already in the first attempt I did not achieve it. By order I have created the packages classes, bean, bo, bo.Spring, dao, dao.Spring with the following code as it corresponds:

This is the code of the JSF page

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Acceso a Sicoca</title>
         <link rel="stylesheet" href="resources/css/estiloLogin.css"></link>
    </h:head>
    <h:body>
        <h1>Bienvenidos a SIPRELI</h1>
        <h:form>
            <table>
                <tr>
                    <td>
                        <h:outputText value="Usuario"/>   
                    </td>
                    <td>
                        <h:inputText id="usuario" value="#{usuarioBean.elUsuario.usuario}" 
                                     rendered="true" label="Error"/>
                    </td>
                </tr>
                <tr>
                    <td>
                        <h:outputText value="Password"/>   
                    </td>
                    <td>
                        <h:inputSecret id="password" value="#{usuarioBean.elUsuario.contrasena}" 
                                       rendered="true" label="Error"/>
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <h:commandButton value="Entrar" action="#{usuarioBean.entrar(usuarioBean.elUsuario)}"/>
                    </td>
                </tr>
            </table>
        </h:form>
    </h:body>
</html>

This is the code of the Bean User

package beans;
import clases.UsuarioLogin;
import bo.spring.IUsuarioBo;
import java.io.Serializable;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.component.html.HtmlDataTable;
import org.springframework.stereotype.Component;'

@Component //Cambio de ManagedBean y eliminacion de Sessionscoped por Component
public class UsuarioBean implements Serializable{
    private UsuarioLogin elUsuario;
    private IUsuarioBo usuarioBo;
    private boolean agregado;
    private FacesMessage msj;
    private List<UsuarioLogin> listaUsuario;
    private HtmlDataTable tableUsuario;'

   public UsuarioBean (){
        elUsuario = new UsuarioLogin();
        // usuarioBo = new UsuarioBo(); // Solo para pruebas y simulaciones
    }

   public String entrar(UsuarioLogin elUsuario){
        boolean existe;
        existe = usuarioBo.entrar(elUsuario); 
        if (existe) {
            return "index.xhtml";
        } else{
            return "";
        }
    }

In the bo package

package bo;
import clases.UsuarioLogin;
import bo.spring.IUsuarioBo;
import dao.spring.IUsuarioDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UsuarioBo implements IUsuarioBo {
 @Autowired
    private IUsuarioDao usuarioDao;
 @Override
    public boolean entrar(UsuarioLogin elUsuario) {
        return usuarioDao.entrar(elUsuario);
    }
    public void setUsuarioDao(IUsuarioDao usuarioDao) {
        this.usuarioDao = usuarioDao;
    }
}

The error that occurs to me is the following

  

Caused by: javax.el.PropertyNotFoundException: /access.xhtml @ 19,69   value="# {userBean.username}": Target Unreachable,   identifier 'userBean' resolved to null

Any help you can give me, I thank you from now on.

JC

    
asked by user80385 20.03.2018 в 17:38
source

1 answer

0

The problem is that you removed the ManagedBean and registered it as an @Component, if what you tried is to inject your UserBo service into the managedBean it should be as follows:

@ManagedProperty("#{iUsuarioBo}") private IUsuarioBo iUsuarioBo ;

    
answered by 20.03.2018 в 20:30