Bom galera, estou horas aqui tentando resolver este problema mais não consegui. Quero salvar meu formulario no Banco de dados, mais não consigo.
Erro Apresentado:
Meu html
`<ui:composition template="/template/layoutpadrao.xhtml"
xmlns=“http://www.w3.org/1999/xhtml”
xmlns:ui=“http://java.sun.com/jsf/facelets”
xmlns:f=“http://java.sun.com/jsf/core”
xmlns:h=“http://java.sun.com/jsf/html”
xmlns:p=“http://primefaces.org/ui”>
<!--Pega os valores do agendamento. -->
<f:metadata>
<f:viewParam name="codigo" value="#{cadastroAgenda.agendamento}" converter="convertAgenda" />
</f:metadata>
<h:outputStylesheet library="css" name="sistema.css" />
<ui:define name="titulo">
#{cadastroAgenda.editando ? 'Editando Agendamento': 'Agendando Cliente'}
</ui:define>
<ui:define name="Botao">
<h:form>
<ui:include src="/template/layoutCabecalho.xhtml" />
</h:form>
</ui:define>
<ui:define name="corpo">
<h:form id="frm">
<br />
<br />
<p:button outcome="consultaagenda" value="consultar agenda" styleClass="letra" />
<br />
<br />
<p:messages closable="true" />
<p:accordionPanel>
<p:tab
title="#{cadastroAgenda.editando ? 'Editando Agendamento' : 'Novo Agendamento'}">
<h:panelGrid columns="2" styleClass="painel" columnClasses="label campo " id="panel">
<p:outputLabel value="Nome" for="nome" />
<p:inputText id="nome" value="#{cadastroAgenda.agendamento.nome}"
size="25" required="true" label="Campo nome" />
<h:outputLabel value="Tel.Celular" for="celular" />
<p:inputText id="celular"
value="#{cadastroAgenda.agendamento.telefoneCelular}" size="14" />
<p:outputLabel value="Tel.Residêncial" for="resi" />
<p:inputText id="resi"
value="#{cadastroAgenda.agendamento.telefoneResidencial}"
size="14" />
<h:outputLabel value="Funcionario" for="func" />
<p:selectOneMenu value="#{cadastroAgenda.agendamento.funcionario}"
required="true" id="func" label="Funcionario">
<f:selectItem itemLabel=" ---Selecione---" noSelectionOption="true" />
<f:selectItems value="#{cadastroAgenda.listfuncionarios}"
var="funcionario" itemLabel="#{funcionario.funcNome}"
itemValue="#{funcionario}" />
</p:selectOneMenu>
<p:outputLabel value="Descrição do Serviço" for="descr" />
<p:inputTextarea id="descr"
value="#{cadastroAgenda.agendamento.descricaoServ}"
style="font-size:13pt;" cols="50" rows="2" required="true"
label="Descrição do Serviço">
<f:validateLength minimum="4" />
</p:inputTextarea>
<p:outputLabel value="Data" for="data" />
<p:calendar value="#{cadastroAgenda.agendamento.data}" size="8"
locale="pt" id="data" required="true" label="Data"
pattern="dd/MM/yyyy">
<f:validator validatorId="domingo" />
</p:calendar>
<p:outputLabel value="Hora" for="hora" />
<p:calendar value="#{cadastroAgenda.agendamento.hora}" id="hora"
size="4" required="true" label="Hora" pattern="HH:mm" locale="pt"
timeOnly="true" minHour="8" maxHour="18">
</p:calendar>
<p:outputLabel value="" />
<h:panelGroup>
<p:commandButton action="#{cadastroAgenda.Incluir()}" value="Salvar" ajax="false" />
<p:commandButton value="Limpar" type="reset" />
</h:panelGroup>
</h:panelGrid>
</p:tab>
</p:accordionPanel>
</h:form>
</ui:define>
</ui:composition>`
Meu Bean
`
package view;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import model.Agendamento;
import model.Funcionario;
import repository.Funcionarios;
import service.GestaoAgendamentos;
import service.RegraNegocioException;
import util.MensagemUtil;
import util.Repositorios;
@ManagedBean
@ViewScoped
public class CadastroAgenda implements Serializable {
private static final long serialVersionUID = -5663797197991061067L;
private Repositorios repositorios = new Repositorios();
private Agendamento agendamento = new Agendamento();
private List<Funcionario> listfuncionarios = new ArrayList<Funcionario>();
/**
* Método de Inicialização, este método nao aparace a implementação apenas
* chamo os métodos que Implementa.
*/
// Vai ser chamado,sempre que meu ManagedBean for criado.
@PostConstruct
public void init() {
Funcionarios funcionarios = repositorios.getFuncionario(); // Minha Interface pega a implementação
this.listfuncionarios = funcionarios.listar(); // chama a implemetação que retorna uma lista do tipo.
}
/**
* Salva o Agendamento
*
* @throws RegraNegocioException
*/
public void Incluir() {
GestaoAgendamentos agendamentos = new GestaoAgendamentos(repositorios.getAgendamento());
try {
agendamentos.salvar(agendamento);
agendamento = new Agendamento();
MensagemUtil.AdicionaMensagem(FacesMessage.SEVERITY_INFO, "Agendamento efetuado com sucesso!!!");
FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
} catch (RegraNegocioException e) {
MensagemUtil.AdicionaMensagem(FacesMessage.SEVERITY_ERROR, e.getMessage());
}
}
public boolean isEditando() {
return this.agendamento.getId() != null;
}
/**
* Método de editar agendamento.
* @return
*/
public Agendamento getAgendamento() {
return agendamento;
}
public void setAgendamento(Agendamento agendamento) throws CloneNotSupportedException {
this.agendamento = agendamento;
if (this.agendamento == null) {
this.agendamento = new Agendamento();
} else {
this.agendamento = (Agendamento) agendamento.clone();
}
}
public List<Funcionario> getListfuncionarios() {
return listfuncionarios;
}
}
`
Meu Conversor
`
package converters;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
import model.Funcionario;
import repository.Funcionarios;
@FacesConverter(value=“conversorFuncionario”)
public class FuncionarioConverter implements Converter {
private Repositorios repositorios = new Repositorios();
@Override
public Object getAsObject(FacesContext context, UIComponent component, String valor) {
Funcionario retorno = null;
Funcionarios funcionarios = this.repositorios.getFuncionario();
if(valor != null && !valor.equals("")){
retorno = funcionarios.porCodigo(new Integer(valor));
if (retorno == null) {
String msg = "Não existe agendamento";
FacesContext facescontext = FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg);
facescontext.addMessage(null, message);
throw new ConverterException(message);
}
}
return retorno;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object valor) {
if(valor != null){
Integer codigo = ((Funcionario) valor).getCodigoFunc();
return codigo == null ? "" : codigo.toString();
}
return null;
}
}
`
