I have a problem when trying to login service in my java web application. As you can see below, there is the HTTP Status 500 error stacktrace - Internal Server Error. I've tried a few things, such as clearing tomcat and rebooting the server. But nothing happens. I put some sysout to debug and none of them appeared on the console.
javax.el.PropertyNotFoundException: /index.xhtml @22,99 value="#{usuarioMBean.user.login}": Target Unreachable, identifier [usuarioMBean] resolved to null
com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
javax.faces.component.UIInput.getConvertedValue(UIInput.java:1046)
javax.faces.component.UIInput.validate(UIInput.java:976)
javax.faces.component.UIInput.executeValidate(UIInput.java:1249)
javax.faces.component.UIInput.processValidators(UIInput.java:712)
javax.faces.component.UIForm.processValidators(UIForm.java:253)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Follow my MBean
package controle;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import dominio.Pessoa;
import dominio.Sindico;
import dominio.TipoPessoa;
import dominio.Usuario;
import servico.PessoaService;
import servico.SindicoService;
import servico.UsuarioService;
@ManagedBean(name="usuarioMBean")
@SessionScoped
public class UsuarioMBean {
private Usuario user;
private List<Usuario> listaUser;
private UsuarioService UserService;
private Usuario usuarioLogado;
private Pessoa morador;
private Sindico administrador;
@Inject
private PessoaService pessoaService;
@Inject
private SindicoService administradorService;
public UsuarioMBean(){
user = new Usuario();
listaUser = new ArrayList<Usuario>();
UserService = new UsuarioService();
}
public Usuario getUser() {
System.out.println("return user");
return user;
}
public void setUser(Usuario user) {
System.out.println("Set user");
this.user = user;
}
public List<Usuario> getListaUser() {
System.out.println("get list user");
return listaUser;
}
public void setListaUser(List<Usuario> listaUser) {
System.out.println("setlistauser");
this.listaUser = listaUser;
}
public Usuario getUsuarioLogado() {
System.out.println("get user logado");
return usuarioLogado;
}
public void setUsuarioLogado(Usuario usuarioLogado) {
System.out.println("set user logado");
this.usuarioLogado = usuarioLogado;
}
public Pessoa getMorador() {
System.out.println("get morador");
return morador;
}
public void setMorador(Pessoa morador) {
System.out.println("set morador");
this.morador = morador;
}
public Sindico getAdministrador() {
System.out.println("get admin");
return administrador;
}
public void setAdministrador(Sindico administrador) {
System.out.println("set admin");
this.administrador = administrador;
}
public String login(){
System.out.println("entrou no STRING LOGIN");
Usuario usuarioBd = new Usuario();
for (Usuario usuarioTemp : UserService.buscarTodos()){
if (usuarioTemp.getLogin() == user.getLogin()){
usuarioBd = usuarioTemp;
}
}
if (usuarioBd.getLogin() != ""){
if (usuarioBd.getSenha().equals(user.getSenha())){
usuarioLogado = usuarioBd;
if (usuarioLogado.getTipoID() == TipoPessoa.morador){
pessoaService = new PessoaService();
morador = pessoaService.buscar(usuarioLogado.getLogin());
return "/index.jsf";
}else{
administradorService = new SindicoService();
//administrador = administradorService.buscar(usuarioLogado.getLogin());
return "/index.jsf";
}
}else{
FacesMessage msg = new FacesMessage("Senha incorreta");
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
FacesContext.getCurrentInstance().addMessage("", msg);
return null;
}
}else{
FacesMessage msg = new FacesMessage("Usuário não existe");
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
FacesContext.getCurrentInstance().addMessage("", msg);
return null;
}
}
public String logoff(){
this.usuarioLogado = null;
return "/login.jsf";
}
}
And jsf
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://xmlns.jcp.org/jsf/passthrough"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough"
>
<h:head>
<title> Condominium::Home </title>
<meta charset="utf-8"/>
<link href="static/css/base.css" rel="stylesheet" />
<link href="static/css/index.css" rel="stylesheet" />
</h:head>
<h:body>
<div class="content">
<div class="login_form">
<h:form>
<h:inputText class="fields" value="#{usuarioMBean.user.login}" a:placeholder="Usuário"/>
<h:inputSecret class="fields" value="#{usuarioMBean.user.senha}" a:placeholder="Senha"/>
<h:commandLink action="#{usuarioMBean.login}" class="submit_button">Logar</h:commandLink>
</h:form>
</div>
</div>
<footer>
<p> Condominium </p>
</footer>