Salve galera, como eu criaria uma action com seam para fazer o seguinte:
1 ? Em uma tela eu tenho um Select que é preenchido com fluxos;
2 ? Ao selecionar um fluxo ele preenche um rich:listShuttle com os itens de fluxo associados e não associados, ou seja ele faz uma consulta no banco passando o id do fluxo como parametro e retorna de um lado os selecionados e de outro os não selecionados.
3 ? O usuário manipula os itens de fluxo pelo controle rich:listShuttle e no final salva, persistindo os itens de fluxo selecionadas no banco.
Se alguém conseguir me ajudar fico muito grato.
package br.com.algartecnologia.save.entity;
import java.io.Serializable;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.Cascade;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
@Entity
@Table(name="tb_Fluxo")
public class Fluxo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="Cod_Fluxo")
private int codigo;
@Column(name="Des_Abreviatura")
@Length(max=20)
private String abreviatura;
@NotNull @Length(max=100)
@Column(name="Nom_Fluxo")
private String nome;
@Length(max=255) @Column(name="Des_Fluxo")
private String descricao;
@NotNull @Column(name="Ind_Ativo")
private int status;
@NotNull @Column(name="Dt_Cadastro")
private Date dataCadastro = new Date();
@OneToMany(fetch = FetchType.LAZY,
mappedBy = "pk.fluxo",
cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
private List<ItemParaFluxo> itensParaFluxo = new LinkedList<ItemParaFluxo>();
public Fluxo() {
}
public Fluxo(String abrev, String nome, String descricao, int status,
Date dataCadastro) {
this.abreviatura = abrev;
this.nome = nome;
this.descricao = descricao;
this.status = status;
this.dataCadastro = dataCadastro;
}
public int getCodigo() {
return codigo;
}
public void setCodigo(int codigo) {
this.codigo = codigo;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public Date getDataCadastro() {
return dataCadastro;
}
public void setDataCadastro(Date dataCadastro) {
this.dataCadastro = dataCadastro;
}
public String getAbreviatura() {
return abreviatura;
}
public void setAbreviatura(String abreviatura) {
this.abreviatura = abreviatura;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + codigo;
result = prime * result
+ ((dataCadastro == null) ? 0 : dataCadastro.hashCode());
result = prime * result
+ ((descricao == null) ? 0 : descricao.hashCode());
result = prime * result + ((nome == null) ? 0 : nome.hashCode());
result = prime * result + status;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Fluxo other = (Fluxo) obj;
if (codigo != other.codigo)
return false;
if (dataCadastro == null) {
if (other.dataCadastro != null)
return false;
} else if (!dataCadastro.equals(other.dataCadastro))
return false;
if (descricao == null) {
if (other.descricao != null)
return false;
} else if (!descricao.equals(other.descricao))
return false;
if (nome == null) {
if (other.nome != null)
return false;
} else if (!nome.equals(other.nome))
return false;
if (status != other.status)
return false;
return true;
}
public void setItemParaFluxo(List<ItemParaFluxo> itensParaFluxo) {
this.itensParaFluxo = itensParaFluxo;
}
public List<ItemParaFluxo> getItemParaFluxo() {
return itensParaFluxo;
}
}
package br.com.algartecnologia.save.entity;
import java.io.Serializable;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.Cascade;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
@Entity
@Table(name="tb_Item_Fluxo")
public class ItemFluxo implements Serializable {
private static final long serialVersionUID = 1L;
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="Cod_Item_Fluxo")
private int codigo;
@NotNull @Length(max=100)
@Column(name="Nom_Item_Fluxo")
private String nome;
@Length(max=255) @Column(name="Des_Item_Fluxo")
private String descricao;
@NotNull @Column(name="Dt_Cadastro")
private Date dataCadastro = new Date();
@NotNull @Column(name="Ind_Ativo")
private int status;
@OneToMany(fetch=FetchType.LAZY, mappedBy = "pk.itemFluxo",
cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private List<ItemParaFluxo> itensParaFluxo = new LinkedList<ItemParaFluxo>();
public ItemFluxo(String nome, String descricao, Date dataCadastro,
int status) {
this.nome = nome;
this.descricao = descricao;
this.dataCadastro = dataCadastro;
this.status = status;
}
public ItemFluxo(int codigo, String nome){
this.codigo = codigo;
this.nome = nome;
}
public ItemFluxo(){}
public int getCodigo() {
return codigo;
}
public void setCodigo(int codigo) {
this.codigo = codigo;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public Date getDataCadastro() {
return dataCadastro;
}
public void setDataCadastro(Date dataCadastro) {
this.dataCadastro = dataCadastro;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + codigo;
result = prime * result
+ ((dataCadastro == null) ? 0 : dataCadastro.hashCode());
result = prime * result
+ ((descricao == null) ? 0 : descricao.hashCode());
result = prime * result + ((nome == null) ? 0 : nome.hashCode());
result = prime * result + status;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ItemFluxo other = (ItemFluxo) obj;
if (codigo != other.codigo)
return false;
if (dataCadastro == null) {
if (other.dataCadastro != null)
return false;
} else if (!dataCadastro.equals(other.dataCadastro))
return false;
if (descricao == null) {
if (other.descricao != null)
return false;
} else if (!descricao.equals(other.descricao))
return false;
if (nome == null) {
if (other.nome != null)
return false;
} else if (!nome.equals(other.nome))
return false;
if (status != other.status)
return false;
return true;
}
@Override
public String toString() {
return this.codigo + ":" + this.nome;
}
public void setItemParaFluxo(List<ItemParaFluxo> itemParaFluxo) {
this.itensParaFluxo = itemParaFluxo;
}
public List<ItemParaFluxo> getItemParaFluxo() {
return itensParaFluxo;
}
}
package br.com.algartecnologia.save.entity;
import java.io.Serializable;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
public class ItemParaFluxoPK implements Serializable {
private static final long serialVersionUID = -563932347348882025L;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
private Fluxo fluxo;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
private ItemFluxo itemFluxo;
public Fluxo getFluxo() {
return fluxo;
}
public void setFluxo(Fluxo fluxo) {
this.fluxo = fluxo;
}
public ItemFluxo getItemFluxo() {
return itemFluxo;
}
public void setItemFluxo(ItemFluxo itemFluxo) {
this.itemFluxo = itemFluxo;
}
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
if (!(o instanceof ItemParaFluxoPK))
return false;
ItemParaFluxoPK that = (ItemParaFluxoPK) o;
if (this.fluxo != null ? !this.fluxo.equals(that.fluxo)
: that.fluxo != null)
return false;
if (this.itemFluxo != null ? !this.itemFluxo.equals(that.itemFluxo)
: that.itemFluxo != null)
return false;
return true;
}
public int hashCode() {
int result;
result = (this.fluxo != null ? this.fluxo.hashCode() : 0);
result = 31 * result
+ (this.itemFluxo != null ? this.itemFluxo.hashCode() : 0);
return result;
}
}
package br.com.algartecnologia.save.entity;
import java.io.Serializable;
import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table(name = "tb_Fluxo_Item_Fluxo")
@AssociationOverrides( {
@AssociationOverride(name = "pk.fluxo", joinColumns = @JoinColumn(name = "Cod_Fluxo")),
@AssociationOverride(name = "pk.itemFluxo", joinColumns = @JoinColumn(name = "Cod_Item_Fluxo")) })
public class ItemParaFluxo implements Serializable {
private static final long serialVersionUID = -860591466706422568L;
@EmbeddedId
private ItemParaFluxoPK pk = new ItemParaFluxoPK();
@Column(name = "Num_Posicao")
private int posicao;
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
ItemParaFluxo that = (ItemParaFluxo) o;
if (getPk() != null ? !getPk().equals(that.getPk())
: that.getPk() != null)
return false;
return true;
}
@Transient
public Fluxo getFluxo() {
return this.getPk().getFluxo();
}
@Transient
public ItemFluxo getItemFluxo() {
return this.getPk().getItemFluxo();
}
public int hashCode() {
return (getPk() != null ? getPk().hashCode() : 0);
}
public ItemParaFluxoPK getPk() {
return pk;
}
public void setPosicao(int posicao) {
this.posicao = posicao;
}
public int getPosicao() {
return posicao;
}
}