maxmustang
posta o ManagedBean e a Classe ae pra ajudar
paulovitor.vanzela
public class TarefaProgHandler {
private Tarefaprogramada tp;
private List<Tarefaprogramada> tarefaProgListagem;
private String status;
private Tarefaprogramada tps;
public TarefaProgHandler() {
tp = new Tarefaprogramada();
status = "incluindo";
carregaLista();
}
public String Novo() {
tp = new Tarefaprogramada();
status = "incluindo";
return "sucesso";
}
public String Cadastrar() {
tp = new Tarefaprogramada();
status = "incluindo";
return "cadastroTp";
}
public String MovimentarTp() {
status = "incluindo";
return "atendimentoTp";
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public List<Tarefaprogramada> getTarefaProgListagem() {
return tarefaProgListagem;
}
public void setTarefaProgListagem(List<Tarefaprogramada> tarefaProgListagem) {
this.tarefaProgListagem = tarefaProgListagem;
}
public Tarefaprogramada getTp() {
return tp;
}
public void setTp(Tarefaprogramada tp) {
this.tp = tp;
}
private void carregaLista() {
Session s = HibernateUtil.currentSession();
Dao<Tarefaprogramada> dao = new Dao<Tarefaprogramada>(s, Tarefaprogramada.class);
this.tarefaProgListagem = dao.list();
}
public String salve() {
Session s = HibernateUtil.currentSession();
Dao<Tarefaprogramada> dao = new Dao<Tarefaprogramada>(s, Tarefaprogramada.class);
if (status.equals("incluindo")) {
dao.save(tp);
tarefaProgListagem.add(tp);
} else {
dao.merge(tp);
carregaLista();
}
return "sucesso";
}
public String busca() {
HttpServletRequest req =
(HttpServletRequest) FacesContext.getCurrentInstance().
getExternalContext().getRequest();
Session s = HibernateUtil.currentSession();
Dao<Tarefaprogramada> dao = new Dao<Tarefaprogramada>(s, Tarefaprogramada.class);
tp = dao.load(Integer.parseInt(req.getParameter("linkId")));
status = "alterando";
return "visualizarChamado";
}
public String exclua() {
HttpServletRequest req =
(HttpServletRequest) FacesContext.getCurrentInstance().
getExternalContext().getRequest();
Session s = HibernateUtil.currentSession();
Dao<Tarefaprogramada> dao = new Dao<Tarefaprogramada>(s, Tarefaprogramada.class);
tp = dao.load(Integer.parseInt(req.getParameter("linkId")));
dao.delete(tp);
carregaLista();
return "mesma_pagina";
}
}
classe associada
package modelo.entidade;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
*
-
@author Paulo
*/
@Entity
@Table(name = “TP_HISTORICO”)
public class TpHistorico implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
<a class="mention" href="/u/basic">@Basic</a>(optional = false)
@Column(name = “TPH_ID”)
private Integer tphId;
<a class="mention" href="/u/basic">@Basic</a>(optional = false)
@Column(name = “TPH_DATAINICIO”)
@Temporal(TemporalType.TIMESTAMP)
private Date tphDatainicio;
<a class="mention" href="/u/basic">@Basic</a>(optional = false)
@Column(name = “TPH_DATATERMINO”)
@Temporal(TemporalType.TIMESTAMP)
private Date tphDatatermino;
<a class="mention" href="/u/basic">@Basic</a>(optional = true)
<a class="mention" href="/u/lob">@Lob</a>
@Column(name = “TPH_DESCRICAO”)
private String tphDescricao;
@JoinColumn(name = “FASE_ID”, referencedColumnName = “FASE_ID”)
@ManyToOne(optional = false)
private Fase tpHfaseId;
@JoinColumn(name = “TP_ID”, referencedColumnName = “TP_ID”)
@ManyToOne(optional = false)
private Tarefaprogramada tphTpId;
@JoinColumn(name = “USUARIO_ID”, referencedColumnName = “USUARIO_ID”)
@ManyToOne(optional = false)
private Usuario usuarioIdHistorico;
public TpHistorico() {
tphId = 0;
tphDatainicio = new Date();
tphDatatermino = new Date();
tphDescricao = “”;
tphTpId = new Tarefaprogramada();
tpHfaseId = new Fase();
usuarioIdHistorico = new Usuario();
tpHfaseId = new Fase();
}
public TpHistorico(Integer tphId) {
this.tphId = tphId;
}
public TpHistorico(Integer tphId, Date tphDatainicio, Date tphDatatermino, String tphDescricao, Fase tpHfaseId, Tarefaprogramada tphTpId, Usuario usuarioIdHistorico) {
this.tphId = tphId;
this.tphDatainicio = tphDatainicio;
this.tphDatatermino = tphDatatermino;
this.tphDescricao = tphDescricao;
this.tpHfaseId = tpHfaseId;
this.tphTpId = tphTpId;
this.usuarioIdHistorico = usuarioIdHistorico;
}
public Integer getTphId() {
return tphId;
}
public void setTphId(Integer tphId) {
this.tphId = tphId;
}
public Date getTphDatainicio() {
return tphDatainicio;
}
public void setTphDatainicio(Date tphDatainicio) {
this.tphDatainicio = tphDatainicio;
}
public Date getTphDatatermino() {
return tphDatatermino;
}
public void setTphDatatermino(Date tphDatatermino) {
this.tphDatatermino = tphDatatermino;
}
public String getTphDescricao() {
return tphDescricao;
}
public void setTphDescricao(String tphDescricao) {
this.tphDescricao = tphDescricao;
}
public Fase getFaseId() {
return tpHfaseId;
}
public void setFaseId(Fase faseId) {
this.tpHfaseId = faseId;
}
public Tarefaprogramada getTpId() {
return tphTpId;
}
public void setTpId(Tarefaprogramada tpId) {
this.tphTpId = tpId;
}
public Usuario getUsuarioIdHistorico() {
return usuarioIdHistorico;
}
public void setUsuarioIdHistorico(Usuario usuarioIdHistorico) {
this.usuarioIdHistorico = usuarioIdHistorico;
}
public Fase getTpHfaseId() {
return tpHfaseId;
}
public void setTpHfaseId(Fase tpHfaseId) {
this.tpHfaseId = tpHfaseId;
}
public Tarefaprogramada getTphTpId() {
return tphTpId;
}
public void setTphTpId(Tarefaprogramada tphTpId) {
this.tphTpId = tphTpId;
}
<a class="mention" href="/u/override">@Override</a>
public int hashCode() {
int hash = 0;
hash += (tphId != null ? tphId.hashCode() : 0);
return hash;
}
<a class="mention" href="/u/override">@Override</a>
public boolean equals(Object object) {
// TODO: Warning - this method won’t work in the case the id fields are not set
if (!(object instanceof TpHistorico)) {
return false;
}
TpHistorico other = (TpHistorico) object;
if ((this.tphId == null && other.tphId != null) || (this.tphId != null && !this.tphId.equals(other.tphId))) {
return false;
}
return true;
}
<a class="mention" href="/u/override">@Override</a>
public String toString() {
return “modelo.entidade.TpHistorico[tphId=” + tphId + “]”;
}
}