Então, estou com um problema ao alterar os dados, se eu coloco serialize ele não mostra o erro, entretanto não altera os dados de qualquer forma, segue os código abaixo.
import java.io.Serializable;
import javax.persistence.*;
@Entity
@Table(name = "TipoLista")
@NamedQueries({
@NamedQuery(name = "tipolista.findAll", query = "SELECT t FROM TipoLista t"),
@NamedQuery(name = "tipolista.count", query = "SELECT COUNT(t) FROM TipoLista t")})
public class TipoLista implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "idtipolista")
private int id;
@Column(name = "descricao")
private String descricao;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
}
import entities.TipoLista;
import java.io.IOException;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.servlet.http.HttpServletRequest;
import repository.TipoListaRepository;
/**
*
* @author daniel
*/
@ManagedBean
@SessionScoped
public class TipoListaBean implements java.io.Serializable {
//@ManagedProperty(value = "#{entityManager}")
//private EntityManager entityManager;
private TipoLista tpLista = new TipoLista();
private List<TipoLista> tpListas;
public void save() throws IOException {
TipoListaRepository tpListaRepository = new TipoListaRepository(this.getManager());
tpListaRepository.save(this.tpLista);
this.tpLista = new TipoLista();
this.tpListas = null;
FacesContext.getCurrentInstance().getExternalContext().redirect("tipolista.xhtml");
}
public String preparaAlterar(TipoLista tpLista) {
this.setTipoLista(tpLista);
return "listagem?faces-redirect=true";
}
public void update() {
TipoListaRepository tpListaRepository = new TipoListaRepository(this.getManager());
tpListaRepository.update(this.tpLista);
this.tpLista = new TipoLista();
this.tpListas = null;
}
public void remove(TipoLista tpLista) {
TipoListaRepository repository = new TipoListaRepository(this.getManager());
repository.remove(tpLista);
this.tpListas = null;
}
public List<TipoLista> getTpListas() {
if (this.tpListas == null) {
TipoListaRepository repository = new TipoListaRepository(this.getManager());
this.tpListas = repository.getTplistas();
}
return this.tpListas;
}
public TipoLista getTpLista() {
return tpLista;
}
public void setTipoLista(TipoLista tpLista) {
this.tpLista = tpLista;
}
private EntityManager getManager() {
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();
HttpServletRequest request = (HttpServletRequest) ec.getRequest();
return (EntityManager) request.getAttribute("entityManager");
}
}
import entities.TipoLista;
import java.util.List;
import javax.persistence.EntityManager;
/**
*
* @author daniel
*/
public class TipoListaRepository {
private EntityManager entityManager;
public TipoListaRepository(EntityManager entityManager) {
this.entityManager = entityManager;
}
public void save(TipoLista tplista) {
this.entityManager.persist(tplista);
this.entityManager.flush();
}
public void remove(TipoLista tpLista) {
//this.entityManager.remove(tpLista);
TipoLista tpListaTemp = new TipoLista();
tpListaTemp = this.entityManager.find(TipoLista.class, tpLista.getId());
this.entityManager.remove(tpListaTemp);
}
public void update(TipoLista tpLista) {
this.entityManager.merge(tpLista);
this.entityManager.flush();
}
@SuppressWarnings("unchecked")
public List<TipoLista> getTplistas() {
return this.entityManager.createNamedQuery("tipolista.findAll")
.getResultList();
}
}
[code]
<f:view>
<h:head>
<title>Tipo de Lista</title>
<style type="text/css">
.ui-widget {font-size: 75% !important;}
</style>
</h:head>
<h:body>
<h:form id="frmGeral">
<p:fieldset legend="Cadastro de Tipo de Lista" toggleable="true">
<p:messages id="messages" />
<h:panelGrid columns="2" id="pnTpListas"
style="font-family: Verdana, Arial; font-weight: bold;">
<h:outputLabel id="lbId" value="*ID" for="id"
style="float: right;" />
<p:inputText id="id" size="60" value="#{tipoListaBean.tpLista.id}"
required="true" requiredMessage="Campo [ID] é obrigatório." />
<h:outputLabel id="lbDescricao" value="*Descrição" for="descricao"
style="float: right;" />
<p:inputText id="descricao" size="60" value="#{tipoListaBean.tpLista.descricao}"
required="true" requiredMessage="Campo [Descrição] é obrigatório." />
</h:panelGrid>
<center>
<h:panelGrid columns="3"
style="font-size: 12px; font-weight: bold;">
<p:commandButton value="Alterar" action="#{tipoListaBean.update()}"
update="frmGeral, messages" />
</h:panelGrid>
</center>
<h:panelGrid columns="2" style="font-family: Verdana, Arial; font-weight: bold;">
<p:dataTable id="dtDVDs" emptyMessage="Nenhum registro encontrado." value="#{tipoListaBean.tpListas}" var="t"
style="text-align: center; font-weight: bold;">
<f:facet name="header">
<h:outputText value="Registro de Tipo de Lista de Compras" />
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="Código"/>
</f:facet>
<h:outputText value="#{t.id}"/>
</p:column>
<p:column id="descricaoColumn" filterBy="#{t.descricao}"
headerText="Filtrar por descrição" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Descrição"/>
</f:facet>
<h:outputText value="#{t.descricao}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Alterar" />
</f:facet>
<h:commandLink value="Alterar">
<p:ajax event="click" listener="#{tipoListaBean.preparaAlterar(t)}"
update="@form" />
</h:commandLink>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Remover"/>
</f:facet>
<f:ajax event="click" render="@form" listener="#{tipoListaBean.remove(t)}">
<h:commandLink value="Remover" />
</f:ajax>
</p:column>
</p:dataTable>
</h:panelGrid>
</p:fieldset>
</h:form>
</h:body>
</f:view>
[/code]
Se alguém puder me ajudar agradeço muito, a mensagem que é exibida é
Advertência: JSF1063: AVISO! Definindo valor de atributo não serializável em HttpSession (chave: dvdBean, classe do valor: managedbeans.DvdBean).
Mas o grande problema é que não altera, salvar ele salvar o problema é alterar o dado mesmo.