Aew pessoal do guj estou com um problema fods…
Tenho uma pagina inserir.jsp e nesta digito 3 valores. Um deles é o nome o outro eh idade e por ultimo tenho um selectOneMenu com objetos endereço.
Ate ai td di boa porem qnd mando a ação de inserir a pagina processa mas volta para ela mesma e não inserindo no banco.
Alguem ja passou por esse problema ?
codigo fonte abaixo.
> jsp
<h:form>
<h1>Inserir Paciente</h1>
<table>
<tr>
<td>
Nome: <h:inputText id="nome" value="#{paciente.paciente.nome}"/>
</td>
</tr>
<tr>
<td>
Idade: <h:inputText value="#{paciente.paciente.idade}"/>
</td>
</tr>
<tr>
<td>
Endereco:
<h:selectOneMenu value="#{paciente.paciente.objEndereco}">
<f:selectItems value="#{endereco.enderecos}" />
</h:selectOneMenu>
</td>
</tr>
<tr>
<td>
<h:commandButton value="Cadastrar" action="#{paciente.doInsert}"/>
</td>
</tr>
</table>
</h:form>
> bean
public class PacienteMB implements AbstractMB{
private Paciente paciente = new Paciente();
public Paciente getPaciente() {
return paciente;
}
public void setPaciente(Paciente paciente) {
this.paciente = paciente;
}
public String doInsert() {
try{
PacienteDAO pdao = MySQLDAOFactory.getInstance().getPacienteDAO();
pdao.insert(paciente);
return "SUCESS";
}catch(Exception e){
e.printStackTrace();
//TO.DO tratar o erro
return "FAIL";
}
}
}
> pojo
public class Paciente {
private String nome;
private int idade;
private Endereco objEndereco;
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public int getIdade() {
return idade;
}
public void setIdade(int idade) {
this.idade = idade;
}
public Endereco getObjEndereco() {
return objEndereco;
}
public void setObjEndereco(Endereco objEndereco) {
this.objEndereco = objEndereco;
}
}
> faces-config.xml
<navigation-rule>
<from-view-id>/cadastrarPaciente.jsp</from-view-id>
<navigation-case>
<from-outcome>SUCESS</from-outcome>
<to-view-id>/sucesso.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>FAIL</from-outcome>
<to-view-id>/erro.jsp</to-view-id>
</navigation-case>
</navigation-rule>
Fico grato se alguem tiver paciencia de me ajudar !!! 