Erro JSF

3 respostas
T

Galera, sou iniciante em JSF, estou desenvolvendo uma aplicação de exemplo q encontrei aqui na web, mas está dando um erro :

[b]HTTP Status 500 -

type Exception report

message

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

exception

javax.servlet.ServletException: java.lang.NullPointerException

root cause

javax.faces.el.EvaluationException: java.lang.NullPointerException

root cause

java.lang.NullPointerException

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.0.1 logs.[/b]

Estou usando o Glassfish… e a IDE Eclipse…

Alguém pode me ajudar???

3 Respostas

A

posta o código e pesquise sobre nullpointerexception, este é o erro mais básico do java ^^

T

Arquivo inserir.jsp:
dy
<f:view>
<h:form>

<h2 align="center">Inserção</h2>
		<br />
		<h3>Entre com os dados abaixo</h3>
		<table>
			<tr>
				<td>Nome:</td>
				<td><h:inputText value="#{agenda.nome}" />
				</td>
			</tr>
			<tr>
				<td>Endereço:</td>
				<td><h:inputText value="#{agenda.endereco}" />
				</td>
			</tr>
			<tr>
				<td>Cidade:</td>
				<td><h:inputText value="#{agenda.cidade}" /></td>
			</tr>
			<tr>
				<td>Telefone:</td>
				<td><h:inputText value="#{agenda.telefone}" /></td>
			</tr>
		</table>
		<p>
			<h:commandButton value="Inserir" action="#{agenda.inserir}" />
		</p>
	</h:form>
	<br>
	<h:outputLink value="index.jsf">
		<f:verbatim>voltar</f:verbatim>
	</h:outputLink>
</f:view>

managed-bean AgendaDB

public class AgendaDB {

private String nome = blank;

private String endereco = blank;

private String cidade = blank;

private String telefone = blank;

private String result_busca = blank;

private String result_inserir = blank;
public static final String BUSCA_INVALIDA = "failure";
public static final String BUSCA_VALIDA = "success";
public static final String SUCESSO_INSERCAO = "success";
public static final String FALHA_INSERCAO = "failure";
static Connection con = null;
static Statement stm = null;
static ResultSet rs;
static private String blank = "";

public AgendaDB() {
		if (con==null) {
			try {
				Class.forName("org.postgresql.Driver");
				con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/agenda","postgres","postgres");
			} catch (SQLException e) {
				System.err.println ("Erro: "+e);
				con = null;
			} catch (ClassNotFoundException e) {
				System.out.println("ClassNotFound...");
				e.printStackTrace();
			}
		}
}

public String getNome() {
	return nome;
}

public void setNome(String nome) {
	this.nome = nome;
}

public String getCidade() {
	return cidade;
}

public void setCidade(String cidade) {
	this.cidade = cidade;
}
			
public String getEndereco() {
	return endereco;
}

public void setEndereco(String endereco) {
	this.endereco = endereco;
}

public String getTelefone() {
	return telefone;
}

public void setTelefone(String telefone) {
	this.telefone = telefone;
}

public String inserir() {
	String result_inserir = FALHA_INSERCAO;
	try {
			stm = con.createStatement();
			stm.execute("INSERT INTO pessoa VALUES ('" + nome + "','"+endereco + "','" + cidade + "','"+ telefone + "')");
			stm.close();
			result_inserir = SUCESSO_INSERCAO;
	} 
	catch (SQLException e) {
			System.err.println ("Erro: "+e);
			result_inserir = FALHA_INSERCAO;
	}
	
	return result_inserir;
}

web.xml

<?xml version="1.0"?> javax.faces.STATE_SAVING_METHOD client javax.faces.CONFIG_FILES /WEB-INF/faces-config.xml com.sun.faces.config.ConfigureListener Faces Servlet javax.faces.webapp.FacesServlet 1 Faces Servlet *.jsf

faces-config.xml

<?xml version="1.0"?> agenda AgendaDB session /busca.jsp success /sucesso_busca.jsp failure /falha_busca.jsp /inserir.jsp success /sucesso_insercao.jsp failure /falha_insercao.jsp
A

dê uma debugada no código antes e me passe o log do stacktrace, não o erro da página que aparece na web que assim posso auxiliá-lo melhor.

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