Duvida JFS

0 respostas
vjfenix

Olá Pessoal!!

Estou estudando Jsf e estou tendo algumas duvida.. se alguém puder ajudar..

Estou criando um formulario para gravar as informações no BD, não tenho certeza se essa é a forma correta. Pois quando dou submit ele retorna a mesma tela sem inserir as informações..

facade

package br.com.csj.facade;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

import br.com.csj.bean.CandidatoVo;
import br.com.csj.bo.CandidatoBo;

public class CandidatoFacade {

	public String inserirCandidato() {
		FacesContext ctx = FacesContext.getCurrentInstance();
		HttpServletRequest request = (HttpServletRequest) ctx
				.getExternalContext().getRequest();
		CandidatoVo vo = new CandidatoVo();
		CandidatoBo bo = new CandidatoBo();
		vo.setId((Integer.parseInt((String) request.getParameter("id"))));
		vo.setNome(request.getParameter("nome"));
		vo.setPrefixo(Integer
				.parseInt((String) request.getParameter("prefixo")));
		vo.setBairro(request.getParameter("bairro"));
		vo.setCidade(request.getParameter("cidade"));
		vo.setComplemento(request.getParameter("complemento"));
		vo.setCpf(Integer.parseInt(request.getParameter("cpf")));
		// vo.setEscolaridade(Object.class(request.getParameter("escolaridade"));
		vo.setLogradouro(request.getParameter("logradouro"));
		vo.setMunicipio(request.getParameter("municipio"));

		bo.inserir(vo);

		return "sucess";
	}

}

JSP

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<html>
<body>
<f:view>
	<h:form >
		<center>
		<h2>Inserir Candidato</h2>
		</center>
		<br>
		<h3>Entre com os dados abaixo</h3>
		<table>
		    <tr>
				<td>Matricula:</td>
				<td><h:inputText value="#{candidato.id}" /></td>
			</tr>
			<tr>
				<td>Nome:</td>
				<td><h:inputText value="#{candidato.nome}" /></td>
			</tr>
			<tr>
				<td>Bairro:</td>
				<td><h:inputText value="#{candidato.bairro}" /></td>
			</tr>
				<td>Cidade:</td>
				<td><h:inputText value="#{candidato.cidade}" size="1" /></td>
			</tr>
			<tr>
				<td>Prefixo:</td>
				<td><h:inputText value="#{candidato.prefixo}" size="1"/></td>
			</tr>	
				<td>Telefone:</td>
				<td><h:inputText value="#{candidato.telefone}" size="8"/></td>
			</tr>
			<tr>
				<td>Complemento:</td>
				<td><h:inputText value="#{candidato.complemento}" /></td>
			</tr>
			<tr>
				<td>Municipio:</td>
				<td><h:inputText value="#{candidato.municipio}" /></td>
			</tr>
			<tr>
				<td>Logradouro:</td>
				<td><h:inputText value="#{candidato.logradouro}" /></td>
			</tr>
			<tr>
				<td>Rg:</td>
				<td><h:inputText value="#{candidato.rg}" /></td>
			</tr>
			<tr>
				<td>Cpf:</td>
				<td><h:inputText value="#{candidato.cpf}" /></td>
			</tr>
			<tr>
				<td>Dta Nascimento:</td>
				<td><h:inputText value="#{candidato.dataNascimento}" /></td>
			</tr>
			<tr>
				<td>Escolaridade:</td>
				<td><h:inputText value="#{candidato.escolaridade}" /></td>
			</tr>
			<tr>
				<td>Sexo:</td>
				<td><h:inputText value="#{candidato.sexo}" /></td>
			</tr>
			<tr>
				<td>Estado Civil:</td>
				<td><h:inputText value="#{candidato.estadoCivil}" /></td>
			</tr>
			<tr>
				<td>Nacionalidade:</td>
				<td><h:inputText value="#{candidato.nacionalidade}" /></td>
			</tr>
			<tr>
				<td>Observacao:</td>
				<td><h:inputText value="#{candidato.observacao}" /></td>
			</tr>
		</table>
		<p><h:commandButton value="ok" action="#{candidatofacade.inserircandidato}"/> 
		</p>
	 
	</h:form>
	<br>
</f:view>
</body>
</html>
<faces-config>
	<navigation-rule>
		<from-view-id>/inserirCandidato.jsp</from-view-id>
		<navigation-case>
			<from-outcome>success</from-outcome>
			<to-view-id>/sucesso_insercao.jsp</to-view-id>
		</navigation-case>
		<navigation-case>
			<from-outcome>failure</from-outcome>
			<to-view-id>/falha_insercao.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
	
	
	<managed-bean>
		<managed-bean-name>candidato</managed-bean-name>
		<managed-bean-class>br.com.csj.bean.CandidatoVo</managed-bean-class>
		<managed-bean-scope>session</managed-bean-scope>
	</managed-bean>
</faces-config>
Criado 19 de julho de 2008
Respostas 0
Participantes 1