Erro no Jsf

2 respostas
vjfenix

Olá pessoal..

Estou estudando o jsf e fiz aum exemplo bem simples para entender o fluxo do mesmo, porém está me dando um erro que não consegui entender o porque. Se alguém puder me ajudar....

public class LoginBean {

    private String login;
    private String senha;

    public String getLogin() {
        return login;
    }    public void setLogin(String login) {
        this.login = login;
    }

    public String getSenha() {
        return senha;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }
    public String logar() {
        if (login.equals("paulojr")) {

            if (senha.equals("123")) {
                return "autorizado";
            }
        }
        FacesContext.getCurrentInstance().addMessage("erro", new FacesMessage("Login não autorizado!"));
        return null;
    }
    }
<?xml version='1.0' encoding='UTF-8'?>

<!-- =========== FULL CONFIGURATION FILE ================================== -->

<faces-config version="1.2" 
              xmlns="http://java.sun.com/xml/ns/javaee" 
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
    
    <managed-bean>
        <managed-bean-name>LoginBean</managed-bean-name>
        <managed-bean-class>LoginBean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
    <navigation-rule>
        <from-view-id>/welcomeJSF.jsp</from-view-id>
        <navigation-case>
            <from-outcome>autorizado</from-outcome>
            <to-view-id>/autenticado.jsp</to-view-id>
            <redirect/>
        </navigation-case>
    </navigation-rule>
</faces-config>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<%--
    This file is an entry point for JavaServer Faces application.
--%>

<html>
    <body>
        <f:view>
            <h:form id="formLogin">
                <h:messages />
                <br />
                <h:outputText value="Login" /> <h:inputText value="#{loginBean.login}" />
                <br />
                <h:outputText value="Senha" /> <h:inputText value="#{loginBean.senha}" />
                <br />
                <h:commandButton action="#{loginBean.logar}" value="Entrar no Sistema" />
            </h:form>
        </f:view>
    </body>
</html>

ERRO:

HTTP Status 500 -

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Target Unreachable, identifier 'loginBean' resolved to null

root cause

javax.el.PropertyNotFoundException: Target Unreachable, identifier 'loginBean' resolved to null

note The full stack traces of the exception and its root causes are available in the Sun Java System Application Server 9.1_01 logs.
Sun Java System Application Server 9.1_01

2 Respostas

R

no managed-bean voce colocou:LoginBean
no jsp voce colocou:loginBean

:lol:

B

o erro é esse que o raf4ever disse.

no arquivo faces-config.xml você atribuiu um nome ao bean: LoginBean
e no seu jsp, você está referenciando o nome: loginBean

por isso está dando erro Target Unreachable, pois loginBean é null.

Espero ter ajudado.
[]s

Criado 27 de julho de 2008
Ultima resposta 27 de jul. de 2008
Respostas 2
Participantes 3